Minor code cleanups free/R_FREE (#12157)

This commit is contained in:
dav1901 2018-11-14 22:23:20 +02:00 committed by Riccardo Schirone
parent f75a940c59
commit c1f30de193
22 changed files with 35 additions and 67 deletions

View File

@ -8,8 +8,7 @@ R_API RAnalCycleFrame *r_anal_cycle_frame_new() {
RAnalCycleFrame *cf = R_NEW0 (RAnalCycleFrame);
if (cf) {
if (!(cf->hooks = r_list_new ())) {
free (cf);
cf = NULL;
R_FREE (cf);
}
}
return cf;

View File

@ -1376,7 +1376,7 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) {
goto exit;
}
free (buf); buf = NULL;
R_FREE (buf);
buf = decompressed_buf;
size = decompressed_size;
}

View File

@ -150,8 +150,7 @@ static size_t consume_locals_r (RBuffer *b, ut64 max, RBinWasmCodeEntry *out) {
}
return j;
beach:
free (out->locals);
out->locals = NULL;
R_FREE (out->locals);
return 0;
}

View File

@ -69,19 +69,16 @@ R_API void r_cmd_alias_free (RCmd *cmd) {
free (cmd->aliases.values[i]);
}
cmd->aliases.count = 0;
free (cmd->aliases.keys);
free (cmd->aliases.values);
R_FREE (cmd->aliases.keys);
R_FREE (cmd->aliases.values);
free (cmd->aliases.remote);
cmd->aliases.keys = NULL;
cmd->aliases.values = NULL;
}
R_API bool r_cmd_alias_del (RCmd *cmd, const char *k) {
int i; // find
for (i = 0; i < cmd->aliases.count; i++) {
if (!k || !strcmp (k, cmd->aliases.keys[i])) {
free (cmd->aliases.values[i]);
cmd->aliases.values[i] = NULL;
R_FREE (cmd->aliases.values[i]);
cmd->aliases.count--;
if (cmd->aliases.count > 0) {
if (i > 0) {
@ -199,8 +196,7 @@ R_API int r_cmd_add(RCmd *c, const char *cmd, const char *desc, r_cmd_callback(c
R_API int r_cmd_del(RCmd *cmd, const char *command) {
int idx = (ut8)command[0];
free (cmd->cmds[idx]);
cmd->cmds[idx] = NULL;
R_FREE (cmd->cmds[idx]);
return 0;
}

View File

@ -447,8 +447,7 @@ rep:
} else {
core->flags->base = r_num_math (core->num, input+1);
}
free (str);
str = NULL;
R_FREE (str);
break;
case '\0':
r_cons_printf ("%"PFMT64d" 0x%"PFMT64x"\n",

View File

@ -587,8 +587,7 @@ static int r_cmd_java_get_cp_bytes_and_write (RCore *core, RBinJavaObj *obj, ut1
return res;
}
free (bytes);
bytes = NULL;
R_FREE (bytes);
if (res == true) {
ut64 n_file_sz = 0;
@ -1891,10 +1890,9 @@ static int r_cmd_java_handle_list_code_references (RCore *core, const char *inpu
operation = strdup ("read constant");
type = r_bin_java_resolve_cp_idx_type (bin, bb->op_bytes[1]);
r_cons_printf (fmt, addr, fcn->name, operation, type, full_bird);
free (full_bird);
free (type);
free (operation);
full_bird = type = operation = NULL;
R_FREE (full_bird);
R_FREE (type);
R_FREE (operation);
} else if ( (bb->type2 & R_ANAL_EX_CODEOP_CALL) == R_ANAL_EX_CODEOP_CALL) {
ut8 op_byte = bb->op_bytes[0];
// look at the bytes determine if it belongs to this class

View File

@ -34,8 +34,7 @@ static char *prompt(const char *str, const char *txt) {
free (r_cons_singleton ()->line->contents);
r_cons_singleton ()->line->contents = strdup (txt);
} else {
free (r_cons_singleton ()->line->contents);
r_cons_singleton ()->line->contents = NULL;
R_FREE (r_cons_singleton ()->line->contents);
}
*cmd = '\0';
r_line_set_prompt (str);
@ -48,8 +47,7 @@ static char *prompt(const char *str, const char *txt) {
}
r_line_set_prompt (oprompt);
free (oprompt);
free (r_cons_singleton ()->line->contents);
r_cons_singleton ()->line->contents = NULL;
R_FREE (r_cons_singleton ()->line->contents);
return res;
}

View File

@ -304,8 +304,7 @@ R_API ut64 r_debug_esil_continue (RDebug *dbg) {
}
static void ewps_free(EsilBreak *ew) {
free (ew->expr);
ew->expr = NULL;
R_FREE (ew->expr);
free (ew);
}

View File

@ -35,8 +35,7 @@ R_API void r_debug_trace_free (RDebugTrace *trace) {
r_list_purge (trace->traces);
free (trace->traces);
sdb_free (trace->db);
free (trace);
trace = NULL;
R_FREE (trace);
}
// TODO: added overlap/mask support here... wtf?

View File

@ -132,10 +132,8 @@ static int __close(RIODesc *fd) {
}
riom = fd->data;
bfvm_free (riom->bfvm);
free (riom->buf);
riom->buf = NULL;
free (fd->data);
fd->data = NULL;
R_FREE (riom->buf);
R_FREE (fd->data);
return 0;
}

View File

@ -49,10 +49,8 @@ static int __close(RIODesc *fd) {
return -1;
}
riom = fd->data;
free (riom->buf);
riom->buf = NULL;
free (fd->data);
fd->data = NULL;
R_FREE (riom->buf);
R_FREE (fd->data);
return 0;
}

View File

@ -107,8 +107,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
static int __close(RIODesc *fd) {
int ret = ptrace (PTRACE_DETACH, RIOPROCPID_PID (fd), 0, 0);
free (fd->data);
fd->data = NULL;
R_FREE (fd->data);
return ret;
}

View File

@ -73,10 +73,8 @@ static int __close(RIODesc *fd) {
return -1;
}
riom = fd->data;
free (riom->url);
riom->url = NULL;
free (fd->data);
fd->data = NULL;
R_FREE (riom->url);
R_FREE (fd->data);
return 0;
}

View File

@ -61,8 +61,7 @@ static int shm__close(RIODesc *fd) {
return -1;
}
ret = shmdt (((RIOShm*)(fd->data))->buf);
free (fd->data);
fd->data = NULL;
R_FREE (fd->data);
return ret;
}

View File

@ -46,10 +46,8 @@ static int __close(RIODesc *fd) {
return -1;
}
riom = fd->data;
free (riom->buf);
riom->buf = NULL;
free (fd->data);
fd->data = NULL;
R_FREE (riom->buf);
R_FREE (fd->data);
return 0;
}

View File

@ -27,8 +27,7 @@ static int w32__close(RIODesc *fd) {
if (fd->data) {
// TODO: handle return value
CloseHandle (RIOW32_HANDLE (fd));
free (fd->data);
fd->data = NULL;
R_FREE (fd->data);
return 0;
}
return -1;

View File

@ -66,8 +66,7 @@ R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bm
}
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free (bmbuf);
bmbuf = NULL;
R_FREE (bmbuf);
}
}
kw = r_search_keyword_new ((ut8 *)kwbuf, strlen (kwbuf), bmbuf, bmlen, data);
@ -94,8 +93,7 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b
}
bmlen = r_hex_str2bin (bmstr, bmbuf);
if (bmlen < 1) {
free(bmbuf);
bmbuf = NULL;
R_FREE (bmbuf);
}
}

View File

@ -130,8 +130,7 @@ R_API bool r_socket_rap_server_continue (RSocketRapServer *rap_s) {
r_socket_write (rap_s->fd, ptr, i);
}
r_socket_flush (rap_s->fd);
free (ptr);
ptr = NULL;
R_FREE (ptr);
break;
case RAP_RMT_CLOSE:
r_socket_read_block (rap_s->fd, &rap_s->buf[1], 4);

View File

@ -92,7 +92,6 @@ R_API void r_cache_flush(RCache *c) {
if (c) {
c->base = 0;
c->len = 0;
free (c->buf);
c->buf = NULL;
R_FREE (c->buf);
}
}

View File

@ -23,8 +23,7 @@ R_API RMemoryPool *r_mem_pool_deinit(RMemoryPool *pool) {
for (i = 0; i < pool->npool; i++) {
free (pool->nodes[i]);
}
free (pool->nodes);
pool->nodes = NULL;
R_FREE (pool->nodes);
return pool;
}

View File

@ -1215,10 +1215,8 @@ static cset * allocset(struct parse *p) {
return(cs);
nomem:
free(p->g->sets);
p->g->sets = NULL;
free(p->g->setbits);
p->g->setbits = NULL;
R_FREE(p->g->sets);
R_FREE(p->g->setbits);
SETERROR(R_REGEX_ESPACE);
/* caller's responsibility not to do set ops */

View File

@ -1587,8 +1587,7 @@ old_proto:
s->next = first;
type->t = VT_FUNC;
type->ref = s;
free (symname);
symname = NULL;
R_FREE (symname);
} else if (tok == '[') {
/* array definition */
next ();