Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert memory leak fix for relocs #4463

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading