public inbox for gdb-testers@sourceware.org help / color / mirror / Atom feed
From: gdb-buildbot@sergiodj.net To: gdb-testers@sourceware.org Subject: [binutils-gdb] libctf: don't leak hash keys or values on value replacement Date: Tue, 08 Oct 2019 03:14:00 -0000 [thread overview] Message-ID: <1820745a0af0768d9dcd515b98ad038ff9f15f23@gdb-build> (raw) *** TEST RESULTS FOR COMMIT 1820745a0af0768d9dcd515b98ad038ff9f15f23 *** commit 1820745a0af0768d9dcd515b98ad038ff9f15f23 Author: Nick Alcock <nick.alcock@oracle.com> AuthorDate: Wed Jul 24 15:21:56 2019 +0100 Commit: Nick Alcock <nick.alcock@oracle.com> CommitDate: Thu Oct 3 17:04:55 2019 +0100 libctf: don't leak hash keys or values on value replacement When a ctf_dynhash_insert() finds a slot already existing, it should call the key and value free functions on the existing key and value and move the passed-in key into place, so that the lifetime rules for hash keys are always the same no matter whether the key existed or not but neither are the keys or values leaked. New in v3. v5: fix tabdamage. libctf/ * ctf-hash.c (ctf_hashtab_insert): Pass in the key and value freeing functions: if set, free the key and value if the slot already exists. Always reassign the key. (ctf_dynhash_insert): Adjust call appropriately. (ctf_hash_insert_type): Likewise. diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 28be757966..08a2e3a536 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,3 +1,11 @@ +2019-07-30 Nick Alcock <nick.alcock@oracle.com> + + * ctf-hash.c (ctf_hashtab_insert): Pass in the key and value + freeing functions: if set, free the key and value if the slot + already exists. Always reassign the key. + (ctf_dynhash_insert): Adjust call appropriately. + (ctf_hash_insert_type): Likewise. + 2019-08-03 Nick Alcock <nick.alcock@oracle.com> * ctf-create.c (ctf_add_type): Look up and use the forwarded-to diff --git a/libctf/ctf-hash.c b/libctf/ctf-hash.c index c6233eb676..59fceed625 100644 --- a/libctf/ctf-hash.c +++ b/libctf/ctf-hash.c @@ -152,7 +152,9 @@ ctf_hashtab_lookup (struct htab *htab, const void *key, enum insert_option inser } static ctf_helem_t * -ctf_hashtab_insert (struct htab *htab, void *key, void *value) +ctf_hashtab_insert (struct htab *htab, void *key, void *value, + ctf_hash_free_fun key_free, + ctf_hash_free_fun value_free) { ctf_helem_t **slot; @@ -169,8 +171,15 @@ ctf_hashtab_insert (struct htab *htab, void *key, void *value) *slot = malloc (sizeof (ctf_helem_t)); if (!*slot) return NULL; - (*slot)->key = key; } + else + { + if (key_free) + key_free ((*slot)->key); + if (value_free) + value_free ((*slot)->value); + } + (*slot)->key = key; (*slot)->value = value; return *slot; } @@ -180,7 +189,8 @@ ctf_dynhash_insert (ctf_dynhash_t *hp, void *key, void *value) { ctf_helem_t *slot; - slot = ctf_hashtab_insert (hp->htab, key, value); + slot = ctf_hashtab_insert (hp->htab, key, value, + hp->key_free, hp->value_free); if (!slot) return errno; @@ -317,7 +327,7 @@ ctf_hash_insert_type (ctf_hash_t *hp, ctf_file_t *fp, uint32_t type, return 0; /* Just ignore empty strings on behalf of caller. */ if (ctf_hashtab_insert ((struct htab *) hp, (char *) str, - (void *) (ptrdiff_t) type) != NULL) + (void *) (ptrdiff_t) type, NULL, NULL) != NULL) return 0; return errno; }
next reply other threads:[~2019-10-08 3:14 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-08 3:14 gdb-buildbot [this message] 2019-10-08 3:14 ` Failures on Ubuntu-Aarch64-m64, branch master gdb-buildbot 2019-10-08 5:34 ` Failures on Ubuntu-Aarch64-native-gdbserver-m64, " gdb-buildbot 2019-10-11 5:24 ` Failures on Fedora-i686, " gdb-buildbot 2019-10-11 6:10 ` Failures on Fedora-x86_64-m64, " gdb-buildbot 2019-10-11 6:34 ` Failures on Fedora-x86_64-native-extended-gdbserver-m32, " gdb-buildbot 2019-10-11 7:06 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot 2019-10-11 7:54 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot
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=1820745a0af0768d9dcd515b98ad038ff9f15f23@gdb-build \ --to=gdb-buildbot@sergiodj.net \ --cc=gdb-testers@sourceware.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: linkBe 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).