Skip to content

Commit

Permalink
Revert "[TO BE REVERTED] Fix memory leaks in linux heap parser (#4426)"
Browse files Browse the repository at this point in the history
This reverts commit 081b3d9.
  • Loading branch information
kazarmy committed May 3, 2024
1 parent 0498345 commit 0cd5349
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
9 changes: 7 additions & 2 deletions librz/bin/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/mdmp/mdmp_pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ RzPVector /*<RzBinImport *>*/ *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;
Expand Down
6 changes: 2 additions & 4 deletions librz/bin/p/bin_mach0.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,9 @@ static RzPVector /*<RzBinReloc *>*/ *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;
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/p/bin_pe.inc
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static RzPVector /*<RzBinImport *>*/ *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];
Expand Down
3 changes: 1 addition & 2 deletions librz/debug/p/native/linux/linux_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/db/formats/pe/imports_tinyW7
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0cd5349

Please sign in to comment.