diff options
author | Mark Wielaard <mjw@redhat.com> | 2015-12-02 16:44:42 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2016-01-02 20:37:45 +0100 |
commit | 3fbd857267a6bffc57225857690aaa383ac58426 (patch) | |
tree | 36dea96c8f13504e88645cac7138d1ccb4a7e3e2 /src/nm.c | |
parent | 5c40529883a48e350b37e7de9ad285facdf84f6f (diff) | |
download | elfutils-3fbd857267a6bffc57225857690aaa383ac58426.tar.gz |
nm: Don't leak duplicate Dwarf local names.
Badly formed DWARF can have duplicate local names. In which case we do
want to detect those so we don't leak the memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Diffstat (limited to 'src/nm.c')
-rw-r--r-- | src/nm.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -708,11 +708,16 @@ get_local_names (Dwarf *dbg) newp->lowpc = lowpc; newp->highpc = highpc; - /* Since we cannot deallocate individual memory we do not test - for duplicates in the tree. This should not happen anyway. */ - if (tsearch (newp, &local_root, local_compare) == NULL) - error (EXIT_FAILURE, errno, - gettext ("cannot create search tree")); + /* Check whether a similar local_name is already in the + cache. That should not happen. But if it does, we + don't want to leak memory. */ + struct local_name **tres = tsearch (newp, &local_root, + local_compare); + if (tres == NULL) + error (EXIT_FAILURE, errno, + gettext ("cannot create search tree")); + else if (*tres != newp) + free (newp); } while (dwarf_siblingof (die, die) == 0); } |