fix some memory leaks reported by coverity

This commit is contained in:
Jeffrey Crowell 2016-07-09 01:41:56 -04:00
parent 0522b93047
commit e65ceb5dee
6 changed files with 12 additions and 2 deletions

View File

@ -80,6 +80,7 @@ R_API RList *r_anal_type_fcn_list (RAnal *anal) {
SdbKv *kv;
if (!list || !sdb_list) {
r_list_free (list);
return 0;
}
ls_foreach (sdb_list, sdb_iter, kv) {

View File

@ -2221,6 +2221,7 @@ RBinElfSymbol* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj_t) *bin, in
eprintf ("Warning: read (sym)\n");
goto beach;
}
free (ret);
ret = calloc (nsym, sizeof (RBinElfSymbol));
if (!ret) {
eprintf ("Cannot allocate %d symbols\n", nsym);

View File

@ -362,13 +362,14 @@ static char *getstring(char *b, int l) {
static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
RCore *core = (RCore *)user;
const bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
ut64 base_addr = 0;
const bool use_color;
if (!core) {
eprintf ("Error: Callback has an invalid RCore.\n");
return false;
}
use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
if (maxhits && searchhits >= maxhits) {
//eprintf ("Error: search.maxhits reached.\n");
return false;

View File

@ -39,8 +39,12 @@ R_API void r_debug_info_free (RDebugInfo *rdi) {
static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem **pb) {
RBreakpointItem *b;
if (!pb) {
eprintf ("BreakpointItem is NULL!\n");
return false;
}
/* initialize the output parameter */
if (pb) *pb = NULL;
*pb = NULL;
/* if we are tracing, update the tracing data */
if (dbg->trace->enabled) {

View File

@ -153,6 +153,7 @@ SDB_API int sdb_array_insert(Sdb *s, const char *key, int idx, const char *val,
} else {
char *nstr = malloc (lstr + 1);
if (!nstr) {
free (x);
return false;
}
memcpy (nstr, str, lstr + 1);

View File

@ -108,6 +108,8 @@ static int foreach_list_cb(void *user, const char *k, const char *v) {
} else {
line = malloc (klen + vlen + 2);
if (!line) {
//XXX coverity complains here that v should be freed.
//v is const, let's const-correctify these.
return 0;
}
memcpy (line, k, klen);