From 2a74bad43d831f2ba9589df2c0666a64b8c3096d Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 15 Jan 2025 12:30:36 +0100 Subject: [PATCH] Resolve more memory leaks in the ELF parser --- libr/bin/bobj.c | 9 ++++++--- libr/bin/p/bin_elf.inc.c | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libr/bin/bobj.c b/libr/bin/bobj.c index fab47ef1171a6..e72bbc5f69914 100644 --- a/libr/bin/bobj.c +++ b/libr/bin/bobj.c @@ -43,6 +43,9 @@ static void object_delete_items(RBinObject *o) { r_list_free (o->strings); ht_up_free (o->strings_db); + if (!RVecRBinImport_empty (&o->imports_vec)) { + RVecRBinImport_fini (&o->imports_vec); + } if (!RVecRBinSymbol_empty (&o->symbols_vec)) { RVecRBinSymbol_fini (&o->symbols_vec); if (o->symbols) { @@ -422,12 +425,12 @@ R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *bo) { } if (bin->filter_rules & (R_BIN_REQ_RELOCS | R_BIN_REQ_IMPORTS)) { if (p->relocs) { - const RList *l = p->relocs (bf); // XXX this is an internal list (should be a vector), and shouldnt be freed by the caller + RList *l = (RList *)p->relocs (bf); // XXX this is an internal list (should be a vector), and shouldnt be freed by the caller if (l) { REBASE_PADDR (bo, l, RBinReloc); bo->relocs = list2rbtree ((RList*)l); - // l->free = NULL; - // r_list_free (l); + l->free = NULL; + r_list_free (l); } } } diff --git a/libr/bin/p/bin_elf.inc.c b/libr/bin/p/bin_elf.inc.c index 324368ff1bc85..9f304503e27b6 100644 --- a/libr/bin/p/bin_elf.inc.c +++ b/libr/bin/p/bin_elf.inc.c @@ -71,6 +71,7 @@ static void destroy(RBinFile *bf) { eo->imports_by_ord[i] = NULL; } } + eo->imports_by_ord_size = 0; R_FREE (eo->imports_by_ord); } RVecRBinElfSymbol_free (eo->phdr_imports_vec);