aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2019-02-12 13:02:48 +0000
committerTom Tromey <tromey@adacore.com>2019-02-12 06:06:19 -0700
commite20773049fde7b9a123fda4485259fc06249b22f (patch)
treec5c01da0056ac3e64cabcdd96b44744e791c4278 /include
parent04d7fa2132c05b962d85e2047646e15b8a490f4e (diff)
downloadgdb-e20773049fde7b9a123fda4485259fc06249b22f.zip
gdb-e20773049fde7b9a123fda4485259fc06249b22f.tar.gz
gdb-e20773049fde7b9a123fda4485259fc06249b22f.tar.bz2
Fix splay tree KEY leak detected in GDB test gdb.base/macscp.exp
When a node is removed from a splay tree, the splay tree was not using the function splay_tree_delete_key_fn to release the key. This was causing a leak, fixed by Tom Tromey. This patch fixes another key leak, that happens when a key equal to a key already present is inserted. In such a case, we have to release the old KEY. Note that this is based on the assumption that the caller always allocates a new KEY when doing an insert. Also, clarify the documentation about when the release functions are called. 2019-02-11 Philippe Waroquiers <philippe.waroquiers@skynet.be> * splay-tree.h (splay_tree_delete_key_fn): Update comment. (splay_tree_delete_value_fn): Likewise. libiberty/ChangeLog 2019-02-11 Philippe Waroquiers <philippe.waroquiers@skynet.be> * splay-tree.c (splay_tree_insert): Also release old KEY in case of insertion of a key equal to an already present key. (splay_tree_new_typed_alloc): Update comment. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@268793 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog5
-rw-r--r--include/splay-tree.h11
2 files changed, 14 insertions, 2 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index a88efc2..2a71eee 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-11 Philippe Waroquiers <philippe.waroquiers@skynet.be>
+
+ * splay-tree.h (splay_tree_delete_key_fn): Update comment.
+ (splay_tree_delete_value_fn): Likewise.
+
2019-01-31 Andreas Krebbel <krebbel@linux.ibm.com>
* opcode/s390.h (enum s390_opcode_cpu_val): Add
diff --git a/include/splay-tree.h b/include/splay-tree.h
index 0d26272..da533de 100644
--- a/include/splay-tree.h
+++ b/include/splay-tree.h
@@ -58,11 +58,18 @@ typedef struct splay_tree_node_s *splay_tree_node;
typedef int (*splay_tree_compare_fn) (splay_tree_key, splay_tree_key);
/* The type of a function used to deallocate any resources associated
- with the key. */
+ with the key. If you provide this function, the splay tree
+ will take the ownership of the memory of the splay_tree_key arg
+ of splay_tree_insert. This function is called to release the keys
+ present in the tree when calling splay_tree_delete or splay_tree_remove.
+ If splay_tree_insert is called with a key equal to a key already
+ present in the tree, the old key and old value will be released. */
typedef void (*splay_tree_delete_key_fn) (splay_tree_key);
/* The type of a function used to deallocate any resources associated
- with the value. */
+ with the value. If you provide this function, the memory of the
+ splay_tree_value arg of splay_tree_insert is managed similarly to
+ the splay_tree_key memory: see splay_tree_delete_key_fn. */
typedef void (*splay_tree_delete_value_fn) (splay_tree_value);
/* The type of a function used to iterate over the tree. */