This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFAv2] Fix leaks in macro definitions.
- From: Simon Marchi <simon dot marchi at ericsson dot com>
- To: Philippe Waroquiers <philippe dot waroquiers at skynet dot be>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, Tom Tromey <tom at tromey dot com>
- Date: Mon, 21 Jan 2019 23:15:24 +0000
- Subject: Re: [RFAv2] Fix leaks in macro definitions.
- References: <20190119172802.25220-1-philippe.waroquiers@skynet.be>
On 2019-01-19 12:28 p.m., Philippe Waroquiers wrote:
> @@ -774,8 +780,28 @@ macro_define_object_internal (struct macro_source_file *source, int line,
> return;
>
> k = new_macro_key (t, name, source, line);
> - d = new_macro_definition (t, macro_object_like, kind, 0, replacement);
> - splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
> + d = new_macro_definition (t, kind, argc, argv, replacement);
> + s = splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d);
> + if ((struct macro_key *) s->key != k)
> + {
> + /* If the node inserted is not using k, it means we have a redefinition.
> + We must free the newly allocated k, as it will not be stored in
> + the splay tree. */
> + macro_tree_delete_key (k);
If this is really the expected behavior, I really think this should be documented in the
splay tree API. It's really a trap everybody will fall into.
You patch LGTM from my point of view, but I'll let Tom give a final OK.
Simon