diff options
author | Mark Wielaard <mark@klomp.org> | 2019-08-29 17:46:52 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2019-08-29 17:46:52 +0200 |
commit | df33285b60290fadefd140ee2fe616f750105d2f (patch) | |
tree | 43ce2d68e113f7a1398f0031fad8533f5e5903ff /src/nm.c | |
parent | bb106065dc6962fabf1c163f18c932650dac6580 (diff) | |
download | elfutils-df33285b60290fadefd140ee2fe616f750105d2f.tar.gz |
nm: Fix latent memory leak in show_symbols.
If there are just a handful of symbols then memory for them is
allocated on the stack, otherwise the memory is malloced. So before
freeing the memory we need to check the number of entries to know if
the memory was heap allocated or not. But since not all entries might
be used we might have decreased the number of entries to the number
we will actually show. Remember the original symbol entries to not
have a memory leak.
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'src/nm.c')
-rw-r--r-- | src/nm.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -1438,6 +1438,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, free (demangle_buffer); #endif /* Now we know the exact number. */ + size_t nentries_orig = nentries; nentries = nentries_used; /* Sort the entries according to the users wishes. */ @@ -1472,7 +1473,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr, } /* Free all memory. */ - if (nentries * sizeof (sym_mem[0]) >= MAX_STACK_ALLOC) + if (nentries_orig * sizeof (sym_mem[0]) >= MAX_STACK_ALLOC) free (sym_mem); obstack_free (&whereob, NULL); |