Fix couple of memory leaks. Issue #2772. (#4725)

This commit is contained in:
Andrey Torsunov 2016-04-28 12:47:50 +04:00 committed by radare
parent 534bc9ddf8
commit 60de2dc6b4
7 changed files with 15 additions and 8 deletions

View File

@ -380,6 +380,7 @@ R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr, const char *str) {
}
len = r_hex_str2bin (str, buf);
r_anal_op (anal, op, addr, buf, len);
free (buf);
return op;
}

View File

@ -339,9 +339,7 @@ R_API int r_anal_fcn_var_del_bydelta (RAnal *a, ut64 fna, const char kind, int s
R_API int r_anal_var_count(RAnal *a, RAnalFunction *fcn, int kind) {
char *varlist;
int count = 0;
RList *list = r_list_new ();
if (!a || !fcn) {
r_list_free (list);
return 0;
}
if (!kind) kind = 'v'; // by default show vars

View File

@ -387,7 +387,11 @@ R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len) {
int numinstr, asmlen, ii;
RAsmCode *c;
if (len<1) return NULL;
if (len < 1) {
r_list_free (hits);
return NULL;
}
buf = (ut8 *)malloc (len);
if (hits == NULL || buf == NULL ){
if (hits) {

View File

@ -1836,6 +1836,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) {
r_core_cmd0 (core, cmd);
}
r_core_cmdf (core, "dp %d", origpid);
r_list_free (list);
}
break;
case 'r':

View File

@ -103,6 +103,7 @@ RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO *io, const char *filename, in
else mmo->fd = r_sandbox_open (filename, O_RDONLY, mode);
if (mmo->fd == -1) {
free (mmo->filename);
free (mmo);
return NULL;
}

View File

@ -40,6 +40,7 @@ static int sparse_read(RList *list, ut64 addr, ut8 *buf, int len) {
}
static RBufferSparse *sparse_append(RList *l, ut64 addr, const ut8 *data, int len) {
if (!data) return NULL;
// TODO: make it more smart to reuse the already sparse items
RBufferSparse *s = R_NEW0 (RBufferSparse);
if (!s) return NULL;
@ -48,12 +49,11 @@ static RBufferSparse *sparse_append(RList *l, ut64 addr, const ut8 *data, int le
s->size = len;
s->odata = NULL;
s->data = calloc (1, len);
if (!data) {
if (!s->data) {
free (s);
return NULL;
} else {
memcpy (s->data, data, len);
}
}
memcpy (s->data, data, len);
if (r_list_append (l, s) == NULL) return NULL;
return s;
}

View File

@ -949,8 +949,10 @@ int r_print_format_struct_size(const char *f, RPrint *p, int mode) {
o = strdup(f);
end = strchr (o, ' ');
fmt = o;
if (!end && !(end = strchr (o, '\0')))
if (!end && !(end = strchr (o, '\0'))) {
free (o);
return -1;
}
if (*end) {
*end = 0;
args = strdup (end+1);