Skip to content

Commit

Permalink
Fix some leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Oct 22, 2024
1 parent bd88186 commit 4231929
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions librz/arch/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,16 @@ RZ_API bool rz_asm_plugin_del(RzAsm *a, RZ_NONNULL RzAsmPlugin *p) {
}

RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name) {
RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
if (!name || !*name) {
return false;
}

RzIterator *iter = ht_sp_as_iter(a->plugins);
RzAsmPlugin **val;
rz_iterator_foreach(iter, val) {
RzAsmPlugin *h = *val;
if (!strcmp(h->name, name)) {
rz_iterator_free(iter);
return true;
}
}
Expand Down Expand Up @@ -470,6 +472,7 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
}
if (h->init && !h->init(&a->plugin_data)) {
RZ_LOG_ERROR("asm plugin '%s' failed to initialize.\n", h->name);
rz_iterator_free(iter);
return false;
}

Expand All @@ -480,6 +483,7 @@ RZ_API bool rz_asm_use(RzAsm *a, RZ_NULLABLE const char *name) {
set_plugin_configs(core, h->name, h->get_config(a->plugin_data));
}
a->cur = h;
rz_iterator_free(iter);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions librz/bin/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,11 @@ RZ_API RzBinPlugin *rz_bin_get_binplugin_by_buffer(RzBin *bin, RzBuffer *buf) {
RzIterator *it = ht_sp_as_iter(bin->plugins);
RzBinPlugin **val;

rz_return_val_if_fail(bin && buf, NULL);

rz_iterator_foreach(it, val) {
RzBinPlugin *plugin = *val;
if (plugin->check_buffer) {
if (plugin->check_buffer(buf)) {
rz_iterator_free(it);
return plugin;
}
}
Expand All @@ -396,6 +395,7 @@ RZ_IPI RzBinPlugin *rz_bin_get_binplugin_by_filename(RzBin *bin) {
RzBinPlugin *plugin = *val;
if (plugin->check_filename) {
if (plugin->check_filename(filename)) {
rz_iterator_free(it);
return plugin;
}
}
Expand Down
1 change: 1 addition & 0 deletions librz/bp/bp_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ RZ_API int rz_bp_use(RZ_NONNULL RzBreakpoint *bp, RZ_NONNULL const char *name) {
RzBreakpointPlugin *h = *val;
if (!strcmp(h->name, name)) {
bp->cur = h;
rz_iterator_free(iter);
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions librz/core/cbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,7 @@ RZ_API RzCmdStatus rz_core_bin_plugins_print(RzBin *bin, RzCmdStateOutput *state
RzBinPlugin *bp = *bp_val;
status = rz_core_bin_plugin_print(bp, state);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
return status;
}
}
Expand All @@ -4922,6 +4923,7 @@ RZ_API RzCmdStatus rz_core_bin_plugins_print(RzBin *bin, RzCmdStateOutput *state
RzBinXtrPlugin *bx = *bx_val;
status = rz_core_binxtr_plugin_print(bx, state);
if (status != RZ_CMD_STATUS_OK) {
rz_iterator_free(iter);
return status;
}
}
Expand Down
3 changes: 3 additions & 0 deletions librz/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,19 @@ RZ_API bool rz_hash_cfg_configure(RZ_NONNULL RzHashCfg *md, RZ_NONNULL const cha
if (is_all || !strcmp(plugin->name, name)) {
mdc = hash_cfg_config_new(plugin);
if (!mdc) {
rz_iterator_free(it);
return false;
}

if (!rz_list_append(md->configurations, mdc)) {
RZ_LOG_ERROR("msg digest: cannot allocate memory for list entry.\n");
hash_cfg_config_free(mdc);
rz_iterator_free(it);
return false;
}

if (!is_all) {
rz_iterator_free(it);
return true;
}
}
Expand Down
2 changes: 2 additions & 0 deletions librz/io/io_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ RZ_API RzIOPlugin *rz_io_plugin_resolve(RzIO *io, const char *filename, bool man
continue;
}
if (ret->check(io, filename, many)) {
rz_iterator_free(iter);
return ret;
}
}
Expand All @@ -80,6 +81,7 @@ RZ_API RzIOPlugin *rz_io_plugin_byname(RzIO *io, const char *name) {
rz_iterator_foreach(iter, val) {
RzIOPlugin *iop = *val;
if (!strcmp(name, iop->name)) {
rz_iterator_free(iter);
return iop;
}
}
Expand Down

0 comments on commit 4231929

Please sign in to comment.