We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs.
The check to see whether we could use stack allocation used the correct
sizeof (GElf_SymX), but the check to see if we needed to free was using
the incorrect sizeof (GElf_Sym). Which could cause us to leak memory.
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
src/ChangeLog | 5 +++++
src/nm.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 7c47079..1b4f1d6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,10 @@
2015-06-18 Mark Wielaard <mjw(a)redhat.com>
+ * nm.c (show_symbols): Check sizeof (GElf_SymX), not GElf_Sym to
+ known whether or not we stack allocated memory.
+
+2015-06-18 Mark Wielaard <mjw(a)redhat.com>
+
* strings.c (readelf): Use "<unknown>" if we cannot retrieve section
name.
diff --git a/src/nm.c b/src/nm.c
index 8d19715..d89bdc7 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -1383,7 +1383,7 @@ show_symbols (Ebl *ebl, GElf_Ehdr *ehdr, Elf_Scn *scn, Elf_Scn
*xndxscn,
}
/* Free all memory. */
- if (nentries * sizeof (GElf_Sym) >= MAX_STACK_ALLOC)
+ if (nentries * sizeof (GElf_SymX) >= MAX_STACK_ALLOC)
free (sym_mem);
obstack_free (&whereob, NULL);
--
1.8.3.1
Show replies by date
On Thu, 2015-06-18 at 11:24 -0700, Roland McGrath wrote:
Use sizeof (sym_mem[0]).
O nice. That way any change in type will be automatically reflected.
Pushed with that change.
Thanks,
Mark