diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 70560c90b1..470ae9c7db 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -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); diff --git a/libr/bin/p/bin_dyldcache.c b/libr/bin/p/bin_dyldcache.c index a5b40ecf62..efaea43d78 100644 --- a/libr/bin/p/bin_dyldcache.c +++ b/libr/bin/p/bin_dyldcache.c @@ -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); diff --git a/libr/bin/pdb/tpi.c b/libr/bin/pdb/tpi.c index f9bc7b5df6..09188eebc8 100644 --- a/libr/bin/pdb/tpi.c +++ b/libr/bin/pdb/tpi.c @@ -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); } diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index 369df55096..fcda4d3f1d 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -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); diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 8128b6837d..b5d15ec70e 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -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); } diff --git a/libr/core/cmd.c b/libr/core/cmd.c index e48299fbe1..44b7c0c617 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -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: diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index 5233eb74da..42d86d0dc1 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -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); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index d18011cf34..c5fe5f31f5 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -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); } } } diff --git a/libr/io/io.c b/libr/io/io.c index 7589894039..1b18b58003 100644 --- a/libr/io/io.c +++ b/libr/io/io.c @@ -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; } } diff --git a/libr/magic/apprentice.c b/libr/magic/apprentice.c index aca4bb230b..e096973916 100644 --- a/libr/magic/apprentice.c +++ b/libr/magic/apprentice.c @@ -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; } diff --git a/libr/reg/arena.c b/libr/reg/arena.c index 8ca8fb8d0d..0183a50cad 100644 --- a/libr/reg/arena.c +++ b/libr/reg/arena.c @@ -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; } diff --git a/libr/socket/r2pipe.c b/libr/socket/r2pipe.c index 78019d881d..a4daa7a1e6 100644 --- a/libr/socket/r2pipe.c +++ b/libr/socket/r2pipe.c @@ -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; diff --git a/libr/util/file.c b/libr/util/file.c index 93349e4942..c6df9b0ba6 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -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__ diff --git a/libr/util/format.c b/libr/util/format.c index 0ec07ca237..b0cdb16153 100644 --- a/libr/util/format.c +++ b/libr/util/format.c @@ -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; } } diff --git a/libr/util/str.c b/libr/util/str.c index 8a764fca03..743a374b7d 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -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; } diff --git a/shlr/sdb/src/disk.c b/shlr/sdb/src/disk.c index 366c5b82a6..9a932bca3a 100644 --- a/shlr/sdb/src/disk.c +++ b/shlr/sdb/src/disk.c @@ -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) { diff --git a/shlr/sdb/src/sdb.c b/shlr/sdb/src/sdb.c index f91a1d0cd0..b54bd33f5e 100644 --- a/shlr/sdb/src/sdb.c +++ b/shlr/sdb/src/sdb.c @@ -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;