Skip to content

Commit

Permalink
Prevent mem leaks.
Browse files Browse the repository at this point in the history
aop possibly holds multiple heap allocated structs.
Those should be freed after usage which wasn't
done here.
  • Loading branch information
Rot127 authored and XVilka committed Nov 29, 2023
1 parent 8b8d5c7 commit e0babbc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions librz/core/casm.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_strsearch(RzCore *core, const ch
ut64 len = RZ_MIN(15, core->blocksize - idx);
if (rz_analysis_op(core->analysis, &aop, addr, buf + idx, len, RZ_ANALYSIS_OP_MASK_BASIC | RZ_ANALYSIS_OP_MASK_DISASM) < 1) {
idx++; // TODO: honor mininstrsz
rz_analysis_op_fini(&aop);
continue;
}
ut64 val = aop.val; // Referenced value
Expand Down Expand Up @@ -285,18 +286,21 @@ RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_strsearch(RzCore *core, const ch
if (!(hit = rz_core_asm_hit_new())) {
rz_list_purge(hits);
RZ_FREE(hits);
rz_analysis_op_fini(&aop);
goto beach;
}
hit->addr = addr;
hit->len = aop.size; // idx + len - tidx;
if (hit->len == -1) {
rz_core_asm_hit_free(hit);
rz_analysis_op_fini(&aop);
goto beach;
}
rz_asm_disassemble(core->rasm, &op, buf + addrbytes * idx,
core->blocksize - addrbytes * idx);
hit->code = rz_str_new(rz_strbuf_get(&op.buf_asm));
rz_asm_op_fini(&op);
rz_analysis_op_fini(&aop);
idx = (matchcount) ? tidx + 1 : idx + 1;
matchcount = 0;
rz_list_append(hits, hit);
Expand All @@ -309,6 +313,7 @@ RZ_API RzList /*<RzCoreAsmHit *>*/ *rz_core_asm_strsearch(RzCore *core, const ch
RzAnalysisOp aop = { 0 };
if (rz_analysis_op(core->analysis, &aop, addr, buf + idx, 15, RZ_ANALYSIS_OP_MASK_ESIL) < 1) {
idx++; // TODO: honor mininstrsz
rz_analysis_op_fini(&aop);
continue;
}
// opsz = aop.size;
Expand Down

0 comments on commit e0babbc

Please sign in to comment.