From ff0addc2b588d21b938a06b2e59ce591656405ee Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Thu, 2 May 2024 20:42:57 +0800 Subject: [PATCH] Revert "[TO BE REVERTED] Fix memory leaks in linux heap parser (#4426)" This reverts commit 6e0a256d7f71e46fcedd4c01588526d3855cee5c. --- librz/bin/bin.c | 9 +++++++-- librz/bin/format/mdmp/mdmp_pe.c | 2 +- librz/bin/p/bin_mach0.c | 6 ++---- librz/bin/p/bin_pe.inc | 2 +- librz/debug/p/native/linux/linux_debug.c | 3 +-- test/db/formats/pe/imports_tinyW7 | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/librz/bin/bin.c b/librz/bin/bin.c index 2e19540ff37..fcd44957574 100644 --- a/librz/bin/bin.c +++ b/librz/bin/bin.c @@ -203,8 +203,13 @@ RZ_API void rz_bin_reloc_free(RZ_NULLABLE RzBinReloc *reloc) { if (!reloc) { return; } - rz_bin_import_free(reloc->import); - rz_bin_symbol_free(reloc->symbol); + /** + * TODO: leak in bin_elf, but it will cause double free in bin_pe if free here, + * Because in the bin_elf implementation RzBinObject->imports and RzBinObject->relocs->imports + * are two pieces of data, but they are linked to each other in bin_pe + */ + // rz_bin_import_free(reloc->import); + // rz_bin_symbol_free(reloc->symbol); free(reloc); } diff --git a/librz/bin/format/mdmp/mdmp_pe.c b/librz/bin/format/mdmp/mdmp_pe.c index 9450cb3ca9a..8fcb7bee276 100644 --- a/librz/bin/format/mdmp/mdmp_pe.c +++ b/librz/bin/format/mdmp/mdmp_pe.c @@ -134,7 +134,7 @@ RzPVector /**/ *PE_(rz_bin_mdmp_pe_get_imports)(struct PE_(rz_bin offset -= pe_bin->vaddr; } rel->additive = 0; - rel->import = rz_bin_import_clone(ptr); + rel->import = ptr; rel->addend = 0; rel->vaddr = offset + pe_bin->vaddr; rel->paddr = imports[i].paddr + pe_bin->paddr; diff --git a/librz/bin/p/bin_mach0.c b/librz/bin/p/bin_mach0.c index d3f0ec69e9c..a8d4a3b5d6a 100644 --- a/librz/bin/p/bin_mach0.c +++ b/librz/bin/p/bin_mach0.c @@ -408,11 +408,9 @@ static RzPVector /**/ *relocs(RzBinFile *bf) { free(ptr); break; } - ptr->import = rz_bin_import_clone(imp); + ptr->import = imp; } else if (reloc->ord >= 0 && reloc->ord < rz_pvector_len(&bin->imports_by_ord)) { - RzBinImport *imp = NULL; - imp = rz_pvector_at(&bin->imports_by_ord, reloc->ord); - ptr->import = rz_bin_import_clone(imp); + ptr->import = rz_pvector_at(&bin->imports_by_ord, reloc->ord); } ptr->addend = reloc->addend; ptr->vaddr = reloc->addr; diff --git a/librz/bin/p/bin_pe.inc b/librz/bin/p/bin_pe.inc index 84bb526e591..bbc00c69a8c 100644 --- a/librz/bin/p/bin_pe.inc +++ b/librz/bin/p/bin_pe.inc @@ -474,7 +474,7 @@ static RzPVector /**/ *imports(RzBinFile *bf) { rel->type = RZ_BIN_RELOC_32; #endif rel->additive = 0; - rel->import = rz_bin_import_clone(ptr); + rel->import = ptr; rel->addend = 0; { ut8 addr[4]; diff --git a/librz/debug/p/native/linux/linux_debug.c b/librz/debug/p/native/linux/linux_debug.c index ed34ab999b4..2d58c104902 100644 --- a/librz/debug/p/native/linux/linux_debug.c +++ b/librz/debug/p/native/linux/linux_debug.c @@ -903,8 +903,7 @@ RZ_API ut64 get_linux_tls_val(RZ_NONNULL RzDebug *dbg, int tid) { } else { tls = rz_reg_get_value(dbg->reg, ri); } -#endif -#if __aarch64__ +#elif __aarch64__ struct iovec iovec = { 0 }; ut64 reg; diff --git a/test/db/formats/pe/imports_tinyW7 b/test/db/formats/pe/imports_tinyW7 index b18932fb4a9..c4a12af454d 100644 --- a/test/db/formats/pe/imports_tinyW7 +++ b/test/db/formats/pe/imports_tinyW7 @@ -18,7 +18,7 @@ vaddr paddr type name 0x800004f4 0x00000234 SET_32 msvcrt_Ordinal_1268 nth vaddr bind type lib name ------------------------------------------------ -284 0x00401048 NONE FUNC kernel32 Ordinal_284 +284 ---------- NONE FUNC kernel32 FindAtomW 1268 0x00401034 NONE FUNC msvcrt Ordinal_1268 EOF RUN