Skip to content

Commit

Permalink
Further mem leak fixes (radareorg#11398)
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored and radare committed Sep 5, 2018
1 parent be913de commit 38d9170
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libr/bin/dwarf.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ static const ut8 *r_bin_dwarf_parse_lnp_header (
if (buf>=buf_end) { buf = NULL; goto beach; }

if (i) {
char *include_dir = NULL, *comp_dir = NULL;
char *include_dir = NULL, *comp_dir = NULL, *pinclude_dir = NULL;
char *allocated_id = NULL;
if (id_idx > 0) {
include_dir = sdb_array_get (s, "includedirs", id_idx - 1, 0);
include_dir = pinclude_dir = sdb_array_get (s, "includedirs", id_idx - 1, 0);
if (include_dir && include_dir[0] != '/') {
comp_dir = sdb_get (bf->sdb_addrinfo, "DW_AT_comp_dir", 0);
if (comp_dir) {
Expand All @@ -334,7 +334,7 @@ static const ut8 *r_bin_dwarf_parse_lnp_header (
}
}
} else {
include_dir = sdb_get (bf->sdb_addrinfo, "DW_AT_comp_dir", 0);
include_dir = pinclude_dir = sdb_get (bf->sdb_addrinfo, "DW_AT_comp_dir", 0);
if (!include_dir)
include_dir = "./";
}
Expand All @@ -351,6 +351,8 @@ static const ut8 *r_bin_dwarf_parse_lnp_header (
hdr->file_names[count].mod_time = mod_time;
hdr->file_names[count].file_len = file_len;
}
free (comp_dir);
free (pinclude_dir);
}
count++;
if (f && i) {
Expand Down Expand Up @@ -730,15 +732,18 @@ R_API int r_bin_dwarf_parse_line_raw2(const RBin *a, const ut8 *obuf,
buf_tmp = buf;
buf = r_bin_dwarf_parse_lnp_header (a->cur, buf, buf_end, &hdr, f, mode);
if (!buf) {
r_bin_dwarf_header_fini (&hdr);
return false;
}
r_bin_dwarf_set_regs_default (&hdr, &regs);
tmplen = (int)(buf_end - buf);
tmplen = R_MIN (tmplen, 4 + hdr.unit_length.part1);
if (tmplen < 1) {
r_bin_dwarf_header_fini (&hdr);
break;
}
if (!r_bin_dwarf_parse_opcodes (a, buf, tmplen, &hdr, &regs, f, mode)) {
r_bin_dwarf_header_fini (&hdr);
break;
}

Expand Down
17 changes: 17 additions & 0 deletions libr/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
bool cmd_tmpseek = false;

if (!cmd) {
r_list_free (tmpenvs);
return 0;
}
cmd = r_str_trim_head_tail (cmd);
Expand All @@ -2051,6 +2052,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
switch (*cmd) {
case '.':
if (cmd[1] == '"') { /* interpret */
r_list_free (tmpenvs);
return r_cmd_call (core->rcmd, cmd);
}
break;
Expand All @@ -2066,6 +2068,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
p = cmd[0] ? find_eoq (cmd + 1) : NULL;
if (!p || !*p) {
eprintf ("Missing \" in (%s).", cmd);
r_list_free (tmpenvs);
return false;
}
*p++ = 0;
Expand Down Expand Up @@ -2160,15 +2163,18 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
cmd = p + 1;
}
}
r_list_free (tmpenvs);
return true;
case '(':
if (cmd[1] != '*' && !strstr (cmd, ")()")) {
r_list_free (tmpenvs);
return r_cmd_call (core->rcmd, cmd);
}
break;
case '?':
if (cmd[1] == '>') {
r_core_cmd_help (core, help_msg_greater_sign);
r_list_free (tmpenvs);
return true;
}
}
Expand All @@ -2191,11 +2197,13 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
int ret ;
*ptr = '\0';
if (r_core_cmd_subst (core, cmd) == -1) {
r_list_free (tmpenvs);
return -1;
}
cmd = ptr + 1;
ret = r_core_cmd_subst (core, cmd);
*ptr = ';';
r_list_free (tmpenvs);
return ret;
//r_cons_flush ();
}
Expand Down Expand Up @@ -2225,6 +2233,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
eprintf (" pd| - disable scr.html and scr.color\n");
eprintf (" pd|H - enable scr.html, respect scr.color\n");
eprintf (" pi 1|T - use scr.tts to speak out the stdout\n");
r_list_free (tmpenvs);
return ret;
} else if (!strncmp (ptr + 1, "H", 1)) { // "|H"
scr_html = r_config_get_i (core->config, "scr.html");
Expand All @@ -2247,6 +2256,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
free (res);
}
core->num->value = value;
r_list_free (tmpenvs);
return 0;
} else { // "|"
scr_html = r_config_get_i (core->config, "scr.html");
Expand Down Expand Up @@ -2274,6 +2284,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
if (scr_color != -1) {
r_config_set_i (core->config, "scr.color", scr_color);
}
r_list_free (tmpenvs);
return ret;
}
for (cmd = ptr + 2; cmd && *cmd == ' '; cmd++);
Expand Down Expand Up @@ -2305,6 +2316,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
if (scr_color != -1) {
r_config_set_i (core->config, "scr.color", scr_color);
}
r_list_free (tmpenvs);
return 0;
}
}
Expand Down Expand Up @@ -2366,6 +2378,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
}
} else {
eprintf ("Cannot slurp with << in non-interactive mode\n");
r_list_free (tmpenvs);
return 0;
}
}
Expand All @@ -2384,6 +2397,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
}
if (ptr[0] && ptr[1] == '?') {
r_core_cmd_help (core, help_msg_greater_sign);
r_list_free (tmpenvs);
return true;
}
int fdn = 1;
Expand Down Expand Up @@ -2452,6 +2466,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
r_config_set_i (core->config, "scr.color", scr_color);
}
core->cons->use_tts = false;
r_list_free (tmpenvs);
return ret;
}
escape_redir:
Expand Down Expand Up @@ -2513,6 +2528,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek
r_config_set_i (core->config, "scr.html", scr_html);
}
free (str);
r_list_free (tmpenvs);
return ret;
}
}
Expand All @@ -2522,6 +2538,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek

if (r_str_endswith (cmd, "~?") && cmd[2] == '\0') {
r_cons_grep_help ();
r_list_free (tmpenvs);
return true;
}
if (*cmd != '.') {
Expand Down

0 comments on commit 38d9170

Please sign in to comment.