aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-02-15 16:09:35 -0700
committerAlan Modra <amodra@gmail.com>2023-02-19 13:17:41 +1030
commit85fc5801281d38897b652b298d35074b7b73ed3a (patch)
treeca0d82b6478f18654299a5f759adec85610d66e6 /bfd
parentcd414f90c340145d811259d10e84b126d73777d0 (diff)
downloadfsf-binutils-gdb-85fc5801281d38897b652b298d35074b7b73ed3a.zip
fsf-binutils-gdb-85fc5801281d38897b652b298d35074b7b73ed3a.tar.gz
fsf-binutils-gdb-85fc5801281d38897b652b298d35074b7b73ed3a.tar.bz2
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. * doc/chew.c (add_variable): New function, from add_intrinsic_variable. (add_intrinsic_variable): Call add_variable. (compile): Call add_variable.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/doc/chew.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c
index 19e3781..cd39969 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