From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Gillespie Newsgroups: gmane.emacs.devel Subject: Re: emacs-29 c9ba05af8d: Fix crashes inside 'xfree' called from treesit.c Date: Wed, 08 Feb 2023 09:43:51 -0600 Message-ID: <95794.1675871031@hassadar.pretzelnet.org> References: <167579964545.12597.15873702837915034838@vcs2.savannah.gnu.org> <20230207195405.BB290C00231@vcs2.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2971"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org, Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Feb 08 17:32:46 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pPnNF-0000Ze-6Z for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Feb 2023 17:32:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pPnMT-0001lx-8s; Wed, 08 Feb 2023 11:31:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPmcC-0005xk-4i for emacs-devel@gnu.org; Wed, 08 Feb 2023 10:44:08 -0500 Original-Received: from relay3-d.mail.gandi.net ([2001:4b98:dc4:8::223]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pPmc5-0000VU-Rm; Wed, 08 Feb 2023 10:44:06 -0500 Original-Received: (Authenticated sender: epg@pretzelnet.org) by mail.gandi.net (Postfix) with ESMTPSA id 8A35460007; Wed, 8 Feb 2023 15:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pretzelnet.org; s=gm1; t=1675871035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vNK9AzjlTE5kNwIbgb8vBmWyJYq+0rBaN2Ffpmd6/fY=; b=mh0+z8cQUTv8fqqB5QR6ZdQm6lRkqSecGtJOqGCD3xBQrACfdvTM+FZzKf0B1tnibElWsb DflmKBO0yt0JcGzKA7T/JAPKhXDPtWbwzC5n6bZ0Bbsly6TCUa33oiKzPCjZhGJTwi55CC myoak6O19A40oV1OuZ14aM6a2WU//XOd0XRRRHxwJ7M/qBa0peRhy2V2Mo6M8Cx3HQpcCt AeKX9FlWXm+D+YjT20SWLYdey5Ei8WGM6btLVKXIV9l3P0iiHlERd9Wh/buMUI4Bm1rI3H 291hoKnU2SaX3uWU3dGMsMfIsOxSToIFDuztxO3IACaq4EvQ1WsKWzMdAs5qVw== In-reply-to: <20230207195405.BB290C00231@vcs2.savannah.gnu.org> X-Mailer: MH-E 8.6+git; nmh 1.7+dev; GNU Emacs 28.1 Content-ID: <95793.1675871031.1@hassadar.pretzelnet.org> Received-SPF: pass client-ip=2001:4b98:dc4:8::223; envelope-from=epg@pretzelnet.org; helo=relay3-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 08 Feb 2023 11:31:54 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:303053 Archived-At: Eli Zaretskii writes: > commit c9ba05af8dfabca00023bd2312dec4ec59497801 > diff --git a/src/treesit.c b/src/treesit.c > index 8e772523cc..b15d44fca0 100644 > --- a/src/treesit.c > +++ b/src/treesit.c > @@ -620,7 +620,7 @@ treesit_load_language (Lisp_Object language_symbol, > char *c_name = xstrdup (SSDATA (base_name)); > treesit_symbol_to_c_name (c_name); > if (found_override) > - c_name = SSDATA (override_c_name); > + c_name = xstrdup (SSDATA (override_c_name)); > langfn = dynlib_sym (handle, c_name); > xfree (c_name); > error = dynlib_error (); Isn't the memory allocated on line 620 (in the initial c_name assignment) leaked when found_override is true? It looks like this dates to commit 1cd42bfb8a5ff2aade43f31b864a8d2cd643d5a3, which, ironically, was fixing another memory leak. It looks like this code has been suffering a lot of memory issues, actually. Maybe I'm misunderstanding, but it looks to me like not only is the memory initially pointed to by c_name leaked, but that that allocation is unnecessary when found_override is true, along with the work done by treesit_symbol_to_c_name. Is this wrong? Thanks! >From 75b5f2822d547c4e3926571661ab7fb4ea4d1317 Mon Sep 17 00:00:00 2001 From: Eric Gillespie Date: Wed, 8 Feb 2023 09:41:20 -0600 Subject: [PATCH] Fix another memory leak in treesit.c * src/treesit.c (treesit_load_language): Always xstrdup 'c_name', always xfree it, and let it go out of scope after free. --- src/treesit.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index b15d44fca01..de8a0962f3b 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -617,12 +617,21 @@ treesit_load_language (Lisp_Object language_symbol, eassume (handle != NULL); dynlib_error (); TSLanguage *(*langfn) (void); - char *c_name = xstrdup (SSDATA (base_name)); - treesit_symbol_to_c_name (c_name); - if (found_override) - c_name = xstrdup (SSDATA (override_c_name)); - langfn = dynlib_sym (handle, c_name); - xfree (c_name); + { + /* c_name must be freed in either case. */ + char *c_name; + if (found_override) + { + c_name = xstrdup (SSDATA (override_c_name)); + } + else + { + c_name = xstrdup (SSDATA (base_name)); + treesit_symbol_to_c_name (c_name); + } + langfn = dynlib_sym (handle, c_name); + xfree (c_name); + } error = dynlib_error (); if (error != NULL) { -- 2.35.3