From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112552 invoked by alias); 3 Dec 2019 21:22:23 -0000 Mailing-List: contact gdb-testers-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-testers-owner@sourceware.org Received: (qmail 112525 invoked by uid 89); 3 Dec 2019 21:22:22 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: kwanyin.sergiodj.net Received: from kwanyin.sergiodj.net (HELO kwanyin.sergiodj.net) (158.69.185.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2019 21:22:19 +0000 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [binutils-gdb] Fix leak of symbol name in block_symbol_cache From: gdb-buildbot@sergiodj.net To: gdb-testers@sourceware.org Message-Id: <82f910ea9cce04b0faabfcd022d9d8949567541e@gdb-build> Date: Tue, 03 Dec 2019 21:22:00 -0000 X-SW-Source: 2019-q4/txt/msg03818.txt.bz2 *** TEST RESULTS FOR COMMIT 82f910ea9cce04b0faabfcd022d9d8949567541e *** commit 82f910ea9cce04b0faabfcd022d9d8949567541e Author: Philippe Waroquiers AuthorDate: Sun Dec 1 17:24:41 2019 +0100 Commit: Philippe Waroquiers CommitDate: Tue Dec 3 21:30:12 2019 +0100 Fix leak of symbol name in block_symbol_cache A symbol not found inserted in the cache has a xstrdup-ed name that must be freed, but only the struct block_symbol_cache is freed. Add a function destroy_block_symbol_cache that clears all slots before releasing the cache. 2019-12-03 Philippe Waroquiers * symtab.c (symbol_cache_clear_slot): Move close to cleared type. (destroy_block_symbol_cache): New function. (symbol_cache:~symbol_cache) Call destroy_block_symbol_cache. (resize_symbol_cache): Likewise. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 59825d3268..5ece688352 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-12-03 Philippe Waroquiers + * symtab.c (symbol_cache_clear_slot): Move close to cleared type. + (destroy_block_symbol_cache): New function. + (symbol_cache:~symbol_cache) Call destroy_block_symbol_cache. + (resize_symbol_cache): Likewise. + 2019-12-02 Tom Tromey * unittests/tui-selftests.c (run_tests): Make conditional. diff --git a/gdb/symtab.c b/gdb/symtab.c index 894a323003..5c33fbf9ab 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -183,6 +183,16 @@ struct symbol_cache_slot } value; }; +/* Clear out SLOT. */ + +static void +symbol_cache_clear_slot (struct symbol_cache_slot *slot) +{ + if (slot->state == SYMBOL_SLOT_NOT_FOUND) + xfree (slot->value.not_found.name); + slot->state = SYMBOL_SLOT_UNUSED; +} + /* Symbols don't specify global vs static block. So keep them in separate caches. */ @@ -201,6 +211,19 @@ struct block_symbol_cache struct symbol_cache_slot symbols[1]; }; +/* Clear all slots of BSC and free BSC. */ + +static void +destroy_block_symbol_cache (struct block_symbol_cache *bsc) +{ + if (bsc != nullptr) + { + for (unsigned int i = 0; i < bsc->size; i++) + symbol_cache_clear_slot (&bsc->symbols[i]); + xfree (bsc); + } +} + /* The symbol cache. Searching for symbols in the static and global blocks over multiple objfiles @@ -217,8 +240,8 @@ struct symbol_cache ~symbol_cache () { - xfree (global_symbols); - xfree (static_symbols); + destroy_block_symbol_cache (global_symbols); + destroy_block_symbol_cache (static_symbols); } struct block_symbol_cache *global_symbols = nullptr; @@ -1234,8 +1257,8 @@ resize_symbol_cache (struct symbol_cache *cache, unsigned int new_size) && new_size == 0)) return; - xfree (cache->global_symbols); - xfree (cache->static_symbols); + destroy_block_symbol_cache (cache->global_symbols); + destroy_block_symbol_cache (cache->static_symbols); if (new_size == 0) { @@ -1373,16 +1396,6 @@ symbol_cache_lookup (struct symbol_cache *cache, return {}; } -/* Clear out SLOT. */ - -static void -symbol_cache_clear_slot (struct symbol_cache_slot *slot) -{ - if (slot->state == SYMBOL_SLOT_NOT_FOUND) - xfree (slot->value.not_found.name); - slot->state = SYMBOL_SLOT_UNUSED; -} - /* Mark SYMBOL as found in SLOT. OBJFILE_CONTEXT is the current objfile when the lookup was done, or NULL if it's not needed to distinguish lookups (STATIC_BLOCK). It is *not*