unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Gillespie <epg@pretzelnet.org>
To: emacs-devel@gnu.org, Eli Zaretskii <eliz@gnu.org>
Subject: Re: emacs-29 c9ba05af8d: Fix crashes inside 'xfree' called from treesit.c
Date: Wed, 08 Feb 2023 09:43:51 -0600	[thread overview]
Message-ID: <95794.1675871031@hassadar.pretzelnet.org> (raw)
In-Reply-To: <20230207195405.BB290C00231@vcs2.savannah.gnu.org>

Eli Zaretskii <eliz@gnu.org> 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 <epg@pretzelnet.org>
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




       reply	other threads:[~2023-02-08 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <167579964545.12597.15873702837915034838@vcs2.savannah.gnu.org>
     [not found] ` <20230207195405.BB290C00231@vcs2.savannah.gnu.org>
2023-02-08 15:43   ` Eric Gillespie [this message]
2023-02-08 16:42     ` emacs-29 c9ba05af8d: Fix crashes inside 'xfree' called from treesit.c Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=95794.1675871031@hassadar.pretzelnet.org \
    --to=epg@pretzelnet.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).