This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFAv2] Fix leaks in macro definitions.


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]