mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-08 02:53:29 +00:00
Fix memleak when using rbin without binding io
This commit is contained in:
parent
9a3787464c
commit
de25f7a0fc
@ -867,20 +867,22 @@ R_API int r_bin_load(RBin *bin, const char *file, ut64 baseaddr, ut64 loadaddr,
|
||||
// ALIAS? return r_bin_load_as (bin, file, baseaddr, loadaddr,
|
||||
// xtr_idx, fd, rawstr, 0, file);
|
||||
RIOBind *iob = &(bin->iob);
|
||||
RIODesc *desc = NULL;
|
||||
RIO *io = (iob && iob->get_io)? iob->get_io (iob): NULL;
|
||||
if (!io) {
|
||||
io = r_io_new ();
|
||||
if (!io) {
|
||||
return false;
|
||||
}
|
||||
bin->io_owned = true;
|
||||
r_io_bind (io, &bin->iob);
|
||||
}
|
||||
bin->rawstr = rawstr;
|
||||
//Use the current RIODesc otherwise r_io_map_select can swap them later on
|
||||
desc = iob->desc_get (io, fd);
|
||||
// Use the current RIODesc otherwise r_io_map_select can swap them later on
|
||||
RIODesc *desc = iob->desc_get (io, fd);
|
||||
if (!desc) {
|
||||
r_io_free (io);
|
||||
memset (&bin->iob, 0, sizeof (bin->iob));
|
||||
bin->io_owned = false;
|
||||
return false;
|
||||
}
|
||||
return r_bin_load_io (bin, desc, baseaddr, loadaddr, xtr_idx);
|
||||
@ -1611,6 +1613,9 @@ R_API void *r_bin_free(RBin *bin) {
|
||||
if (!bin) {
|
||||
return NULL;
|
||||
}
|
||||
if (bin->io_owned) {
|
||||
r_io_free (bin->iob.io);
|
||||
}
|
||||
bin->file = NULL;
|
||||
free (bin->force);
|
||||
free (bin->srcdir);
|
||||
@ -1997,6 +2002,7 @@ R_API RBin *r_bin_new() {
|
||||
bin->minstrlen = 0;
|
||||
bin->want_dbginfo = true;
|
||||
bin->cur = NULL;
|
||||
bin->io_owned = false;
|
||||
|
||||
bin->binfiles = r_list_newf ((RListFree)r_bin_file_free);
|
||||
for (i = 0; bin_static_plugins[i]; i++) {
|
||||
|
@ -1714,8 +1714,7 @@ R_API bool r_core_init(RCore *core) {
|
||||
core->anal->cb.on_fcn_new = on_fcn_new;
|
||||
core->anal->cb.on_fcn_delete = on_fcn_delete;
|
||||
core->anal->cb.on_fcn_rename = on_fcn_rename;
|
||||
core->assembler->syscall = \
|
||||
core->anal->syscall; // BIND syscall anal/asm
|
||||
core->assembler->syscall = core->anal->syscall; // BIND syscall anal/asm
|
||||
r_anal_set_user_ptr (core->anal, core);
|
||||
core->anal->cb_printf = (void *) r_cons_printf;
|
||||
core->parser = r_parse_new ();
|
||||
@ -1739,7 +1738,7 @@ R_API bool r_core_init(RCore *core) {
|
||||
core->graph = r_agraph_new (r_cons_canvas_new (1, 1));
|
||||
core->graph->need_reload_nodes = false;
|
||||
core->asmqjmps_size = R_CORE_ASMQJMPS_NUM;
|
||||
if (sizeof(ut64) * core->asmqjmps_size < core->asmqjmps_size) {
|
||||
if (sizeof (ut64) * core->asmqjmps_size < core->asmqjmps_size) {
|
||||
core->asmqjmps_size = 0;
|
||||
core->asmqjmps = NULL;
|
||||
} else {
|
||||
|
@ -276,6 +276,7 @@ typedef struct r_bin_t {
|
||||
ut64 filter_rules;
|
||||
bool demanglercmd;
|
||||
bool verbose;
|
||||
bool io_owned;
|
||||
} RBin;
|
||||
|
||||
typedef struct r_bin_xtr_metadata_t {
|
||||
|
Loading…
Reference in New Issue
Block a user