Re: [RFA] Fix leaks in macro definitions.

Tom Tromey
2019-01-15T18:50:45Z

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

Simon> Ok. Fixing this in the splay tree code would be a quite long task
Simon> (reviewing all usages in binutils-gdb and gcc, I don't think this code
Simon> is available externally?), so I am ok with this patch which fixes the
Simon> issue in the mean time. Tom?

Actually, I just misunderstood the patch and/or the splay-tree API.

For some of the patch, the splay tree is doing the right thing.
This applies to the macro_define_* patches.

This though:

@@ -841,8 +850,10 @@ macro_undef (struct macro_source_file *source, int line,
arguments like '-DFOO -UFOO -DFOO=2'. */
if (source == key->start_file
&& line == key->start_line)
- splay_tree_remove (source->table->definitions, n->key);
-
+ {
+ splay_tree_remove (source->table->definitions, n->key);
+ macro_tree_delete_key (key);
+ }
else
{
/* This function is the only place a macro's end-of-scope

This one seems like it is definitely a splay-tree bug. The issue is
that it deletes a node but not the node's key.

I think it would be best by far to fix this in splay_tree_remove.
I agree it's hard, but working around this seems worse to me.

Tom