From: Tom Tromey <tom@tromey.com>
To: gcc-patches@gcc.gnu.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Fix leak in splay-tree
Date: Fri, 18 Jan 2019 21:27:00 -0000 [thread overview]
Message-ID: <20190118212730.10803-1-tom@tromey.com> (raw)
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 | 4 ++++
libiberty/splay-tree.c | 2 ++
2 files changed, 6 insertions(+)
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index bcc0227bdd8..1eb25f928f2 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,7 @@
+2019-01-18 Tom Tromey <tom@tromey.com>
+
+ * splay-tree.c (splay_tree_remove): Delete the key if necessary.
+
2019-01-14 Tom Honermann <tom@honermann.net>
* cp-demangle.c (cplus_demangle_builtin_types)
diff --git a/libiberty/splay-tree.c b/libiberty/splay-tree.c
index 920e68db2cb..21d23c38dfc 100644
--- a/libiberty/splay-tree.c
+++ b/libiberty/splay-tree.c
@@ -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);
--
2.17.2
next reply other threads:[~2019-01-18 21:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 21:27 Tom Tromey [this message]
2019-01-21 8:11 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190118212730.10803-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).