Minor code cleanups free/R_FREE (#12145)

This commit is contained in:
dav1901 2018-11-14 00:41:28 +02:00 committed by radare
parent 5759f217c9
commit 8b83d03c99
17 changed files with 37 additions and 72 deletions

View File

@ -1336,8 +1336,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
case LC_LOAD_DYLINKER:
{
sdb_set (bin->kv, sdb_fmt ("mach0_cmd_%d.cmd", i), "dylinker", 0);
free (bin->intrp);
bin->intrp = NULL;
R_FREE (bin->intrp);
//bprintf ("[mach0] load dynamic linker\n");
struct dylinker_command dy = {0};
ut8 sdy[sizeof (struct dylinker_command)] = {0};
@ -1431,8 +1430,7 @@ static int init_items(struct MACH0_(obj_t)* bin) {
return false;
}
if (r_buf_read_at (bin->b, off, dyldi, sizeof (struct dyld_info_command)) == -1) {
free (bin->dyld_info);
bin->dyld_info = NULL;
R_FREE (bin->dyld_info);
bprintf ("Error: read (LC_DYLD_INFO) at 0x%08"PFMT64x"\n", off);
} else {
bin->dyld_info->cmd = r_read_ble32 (&dyldi[0], bin->big_endian);

View File

@ -48,8 +48,7 @@ static void free_bin(RDyldBinImage *bin) {
}
if (bin->file) {
free (bin->file);
bin->file = NULL;
R_FREE (bin->file);
}
R_FREE (bin);
@ -61,18 +60,15 @@ static void rebase_info_free(RDyldRebaseInfo *rebase_info) {
}
if (rebase_info->page_starts) {
free (rebase_info->page_starts);
rebase_info->page_starts = NULL;
R_FREE (rebase_info->page_starts);
}
if (rebase_info->page_extras) {
free (rebase_info->page_extras);
rebase_info->page_extras = NULL;
R_FREE (rebase_info->page_extras);
}
if (rebase_info->one_page_buf) {
free (rebase_info->one_page_buf);
rebase_info->one_page_buf = NULL;
R_FREE (rebase_info->one_page_buf);
}
R_FREE (rebase_info);
@ -99,18 +95,15 @@ static void r_dyldcache_free(RDyldCache *cache) {
}
if (cache->hdr) {
free (cache->hdr);
cache->hdr = NULL;
R_FREE (cache->hdr);
}
if (cache->maps) {
free (cache->maps);
cache->maps = NULL;
R_FREE (cache->maps);
}
if (cache->accel) {
free (cache->accel);
cache->accel = NULL;
R_FREE (cache->accel);
}
R_FREE (cache);

View File

@ -986,8 +986,7 @@ static void free_tpi_stream(void *stream) {
type->type_data.free_ = 0;
type->type_data.type_info = 0;
}
free (type);
type = NULL;
R_FREE (type);
}
r_list_free (tpi_stream->types);
}

View File

@ -372,8 +372,7 @@ R_API void r_line_hist_free() {
int i;
if (I.history.data) {
for (i = 0; i < I.history.size; i++) {
free (I.history.data[i]);
I.history.data[i] = NULL;
R_FREE (I.history.data[i]);
}
}
R_FREE (I.history.data);

View File

@ -693,8 +693,7 @@ static int cb_asmfeatures(void *user, void *data) {
print_node_options (node);
return 0;
}
free (core->assembler->features);
core->assembler->features = NULL;
R_FREE (core->assembler->features);
if (node->value[0]) {
core->assembler->features = strdup (node->value);
}

View File

@ -2300,8 +2300,7 @@ escape_pipe:
}
/* Out Of Band Input */
free (core->oobi);
core->oobi = NULL;
R_FREE (core->oobi);
ptr = strstr (cmd, "?*");
if (ptr && (ptr == cmd || ptr[-1] != '~')) {
@ -3546,8 +3545,7 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) {
r_list_free (match_flag_items);
core->flags->space_idx = flagspace;
core->rcmd->macro.counter++ ;
free (word);
word = NULL;
R_FREE (word);
}
}
}
@ -3635,8 +3633,7 @@ R_API int r_core_cmd(RCore *core, const char *cstr, int log) {
if (core->cmd_depth < 1) {
eprintf ("r_core_cmd: That was too deep (%s)...\n", cmd);
free (ocmd);
free (core->oobi);
core->oobi = NULL;
R_FREE (core->oobi);
core->oobi_len = 0;
goto beach;
}
@ -3660,8 +3657,7 @@ R_API int r_core_cmd(RCore *core, const char *cstr, int log) {
run_pending_anal (core);
core->cmd_depth++;
free (ocmd);
free (core->oobi);
core->oobi = NULL;
R_FREE (core->oobi);
core->oobi_len = 0;
return ret;
beach:

View File

@ -1347,8 +1347,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) {
for (j = 0; j < nb_cols; j++) {
setcolor = true;
free (note[j]);
note[j] = NULL;
R_FREE (note[j]);
// collect comments
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr + j);

View File

@ -2826,8 +2826,7 @@ static int ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx) {
}
}
if (MI.str) {
free (MI.str);
MI.str = NULL;
R_FREE (MI.str);
}
}
}

View File

@ -634,8 +634,7 @@ static ptrace_wrap_instance *io_ptrace_wrap_instance(RIO *io) {
return NULL;
}
if (ptrace_wrap_instance_start (io->ptrace_wrap) < 0) {
free (io->ptrace_wrap);
io->ptrace_wrap = NULL;
R_FREE (io->ptrace_wrap);
return NULL;
}
}

View File

@ -256,8 +256,7 @@ void file_delmagic(struct r_magic *p, int type, size_t entries) {
p--;
/*FALLTHROUGH*/
case 0:
free (p);
p = NULL;
R_FREE (p);
break;
default:
abort ();
@ -307,8 +306,7 @@ struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) {
}
if (errs == -1) {
free (mfn);
free (mlist);
mlist = NULL;
R_FREE (mlist);
file_error (ms, 0, "could not find any magic files!");
return NULL;
}

View File

@ -142,8 +142,7 @@ R_API int r_reg_fit_arena(RReg *reg) {
newsize = R_MAX (size, newsize);
}
if (newsize < 1) {
free (arena->bytes);
arena->bytes = NULL;
R_FREE (arena->bytes);
arena->size = 0;
} else {
ut8 *buf = realloc (arena->bytes, newsize);
@ -167,8 +166,7 @@ R_API RRegArena *r_reg_arena_new(int size) {
size = 1;
}
if (!(arena->bytes = calloc (1, size + 8))) {
free (arena);
arena = NULL;
R_FREE (arena);
} else {
arena->size = size;
}

View File

@ -89,8 +89,7 @@ R_API char *r2p_read(R2Pipe *r2p) {
bufsz += 4096;
newbuf = realloc (buf, bufsz);
if (!newbuf) {
free (buf);
buf = NULL;
R_FREE (buf);
break;
}
buf = newbuf;

View File

@ -786,8 +786,7 @@ static RMmap *r_file_mmap_unix (RMmap *m, int fd) {
m->rw?PROT_READ|PROT_WRITE:PROT_READ,
MAP_SHARED, fd, (off_t)m->base);
if (m->buf == MAP_FAILED) {
free (m);
m = NULL;
R_FREE (m);
}
return m;
}
@ -820,8 +819,7 @@ err_r_file_mmap_windows:
if (m->fh != INVALID_HANDLE_VALUE) {
CloseHandle (m->fh);
}
free (m);
m = NULL;
R_FREE (m);
}
free (file_);
return m;
@ -834,8 +832,7 @@ static RMmap *r_file_mmap_other (RMmap *m) {
lseek (m->fd, (off_t)0, SEEK_SET);
read (m->fd, m->buf, m->len);
} else {
free (m);
m = NULL;
R_FREE (m);
}
return m;
}
@ -1023,8 +1020,7 @@ R_API char *r_file_tmpdir() {
#else
char *path = r_sys_getenv ("TMPDIR");
if (path && !*path) {
free (path);
path = NULL;
R_FREE (path);
}
if (!path) {
#if __ANDROID__

View File

@ -2084,8 +2084,8 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
p->cb_printf ("f %s=0x%08" PFMT64x "\n", fieldname, seeki);
}
if (newname) {
free (newname);
newname = fieldname = NULL;
R_FREE (newname);
fieldname = NULL;
}
}

View File

@ -968,9 +968,8 @@ R_API char* r_str_replace(char *str, const char *key, const char *val, int g) {
newstr = realloc (str, slen + klen + 1);
if (!newstr) {
eprintf ("realloc fail\n");
free (str);
R_FREE (str);
free (scnd);
str = NULL;
break;
}
str = newstr;
@ -1036,9 +1035,8 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen,
newstr = realloc (str, slen + klen);
if (!newstr) {
eprintf ("realloc fail\n");
free (str);
R_FREE (str);
free (scnd);
str = NULL;
break;
}
str = newstr;
@ -3027,8 +3025,7 @@ R_API wchar_t* r_str_mb_to_wc_l(const char *buf, int len) {
fail = false;
err_r_str_mb_to_wc:
if (fail) {
free (res_buf);
res_buf = NULL;
R_FREE (res_buf);
}
return res_buf;
}
@ -3056,8 +3053,7 @@ R_API char* r_str_wc_to_mb_l(const wchar_t *buf, int len) {
fail = false;
err_r_str_wc_to_mb:
if (fail) {
free (res_buf);
res_buf = NULL;
R_FREE (res_buf);
}
return res_buf;
}

View File

@ -163,8 +163,7 @@ SDB_API bool sdb_disk_finish (Sdb* s) {
IFRET (rename (s->ndump, s->dir));
}
#endif
free (s->ndump);
s->ndump = NULL;
R_FREE (s->ndump);
// reopen if was open before
reopen = true; // always reopen if possible
if (reopen) {

View File

@ -431,8 +431,7 @@ SDB_API void sdb_close(Sdb *s) {
s->fd = -1;
}
if (s->dir) {
free (s->dir);
s->dir = NULL;
R_FREE (s->dir);
}
}
}
@ -948,8 +947,7 @@ SDB_API bool sdb_dump_dupnext(Sdb* s, char *key, char **value, int *_vlen) {
return false;
}
if (getbytes (s, *value, vlen) == -1) {
free (*value);
*value = NULL;
R_FREE (*value);
return false;
}
(*value)[vlen] = 0;