[PATCH 7/8] Use @deftypefn in chew output

Tom Tromey tom@tromey.com
Wed Feb 15 23:11:44 GMT 2023


>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> Starting with this commit, I see this when building (with ASan enabled):

Oops, sorry about that.  This patch should fix it.  Let me know what you
think.

Tom

commit 482e9a3e3a3aee643d671d2594be709446cef065
Author: Tom Tromey <tom@tromey.com>
Date:   Wed Feb 15 16:09:35 2023 -0700

    Avoid memory leak in chew
    
    An earlier patch of mine introduced a memory leak in chew.  The bug
    was that the new "variable" word didn't free the following word.  This
    patch fixes it by arranging to transfer ownership of the name to the
    variable itself.
    
    bfd/ChangeLog
    2023-02-15  Tom Tromey  <tom@tromey.com>
    
            * doc/chew.c (add_variable): New function, from
            add_intrinsic_variable.
            (add_intrinsic_variable): Call add_variable.
            (compile): Call add_variable.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e160e4472df..5bf3e9f0919 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2023-02-15  Tom Tromey  <tom@tromey.com>
+
+	* doc/chew.c (add_variable): New function, from
+	add_intrinsic_variable.
+	(add_intrinsic_variable): Call add_variable.
+	(compile): Call add_variable.
+
 2023-02-07  Tom Tromey  <tom@tromey.com>
 
 	* bfd.c, cache.c, compress.c, opncls.c: Remove RETURNS from
diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c
index 19e3781bdda..cd399697abd 100644
--- a/bfd/doc/chew.c
+++ b/bfd/doc/chew.c
@@ -1241,9 +1241,9 @@ add_intrinsic (char *name, void (*func) (void))
 }
 
 static void
-add_intrinsic_variable (char *name, intptr_t *loc)
+add_variable (char *name, intptr_t *loc)
 {
-  dict_type *new_d = newentry (xstrdup (name));
+  dict_type *new_d = newentry (name);
   pcu p = { push_variable };
   add_to_definition (new_d, p);
   p.l = (intptr_t) loc;
@@ -1252,6 +1252,12 @@ add_intrinsic_variable (char *name, intptr_t *loc)
   add_to_definition (new_d, p);
 }
 
+static void
+add_intrinsic_variable (const char *name, intptr_t *loc)
+{
+  add_variable (xstrdup (name), loc);
+}
+
 void
 compile (char *string)
 {
@@ -1333,7 +1339,7 @@ compile (char *string)
 	    continue;
 	  intptr_t *loc = xmalloc (sizeof (intptr_t));
 	  *loc = 0;
-	  add_intrinsic_variable (word, loc);
+	  add_variable (word, loc);
 	  string = nextword (string, &word);
 	}
       else


More information about the Binutils mailing list