Fix leak in splay-tree
authorTom Tromey <tom@tromey.com>
Mon, 21 Jan 2019 15:41:28 +0000 (08:41 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 21 Jan 2019 16:05:01 +0000 (09:05 -0700)
Philippe Waroquiers noticed a memory leak in gdb, which he tracked
down to a bug in splay-tree.  splay_tree_remove does not call the
`delete_key' function when it removes the old node; but it should.

I looked at every splay tree in GCC and there is only one that passes
a non-NULL delete function -- the one in lto.c.  That file does not
call splay_tree_remove.  So, I think this is safe to check in.

I re-ran the LTO tests to double check.

libiberty/
* splay-tree.c (splay_tree_remove): Delete the key if necessary.

libiberty/ChangeLog
libiberty/splay-tree.c

index 436fb96255ce5b895ad86dd8d077e7b3a869f7cd..496d76d3ff4906fb5adc81d4db62e5f727a56869 100644 (file)
@@ -1,3 +1,7 @@
+2019-01-21  Tom Tromey  <tom@tromey.com>
+
+       * splay-tree.c (splay_tree_remove): Delete the key if necessary.
+
 2019-01-01  Jakub Jelinek  <jakub@redhat.com>
 
        Update copyright years.
index 920e68db2cbb2bd1adb36f0e51236cf983c8ab45..21d23c38dfc01d5a93846cafb572b94de8597539 100644 (file)
@@ -425,6 +425,8 @@ splay_tree_remove (splay_tree sp, splay_tree_key key)
       right = sp->root->right;
 
       /* Delete the root node itself.  */
+      if (sp->delete_key)
+       (*sp->delete_key) (sp->root->key);
       if (sp->delete_value)
        (*sp->delete_value) (sp->root->value);
       (*sp->deallocate) (sp->root, sp->allocate_data);
This page took 0.028637 seconds and 4 git commands to generate.