From b401b11f2628a24da697e35328fa0809d0eb432b Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Mon, 16 Oct 2017 15:18:05 +0300 Subject: [PATCH] Minor memory leak fixes for pf. --- libr/bin/bin.c | 1 + libr/bin/pdb/omap.c | 4 ++++ libr/bin/pdb/pdb.c | 14 +++++++------- libr/core/cmd_type.c | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libr/bin/bin.c b/libr/bin/bin.c index 4925948d5e..4349ad685f 100644 --- a/libr/bin/bin.c +++ b/libr/bin/bin.c @@ -930,6 +930,7 @@ R_API int r_bin_reload(RBin *bin, int fd, ut64 baseaddr) { if (!bf) { return false; } + the_obj_list = bf->objs; bf->objs = r_list_newf ((RListFree)r_bin_object_free); // invalidate current object reference diff --git a/libr/bin/pdb/omap.c b/libr/bin/pdb/omap.c index 74b6cfbe7a..1830dd7f88 100644 --- a/libr/bin/pdb/omap.c +++ b/libr/bin/pdb/omap.c @@ -112,6 +112,10 @@ int omap_remap(void *stream, int address) { // mb (len -1) ??? pos = binary_search (omap_stream->froms, address, 0, (len)); + if (pos == -1) { + return -1; + } + if (omap_stream->froms[pos] != address) { pos -= 1; } diff --git a/libr/bin/pdb/pdb.c b/libr/bin/pdb/pdb.c index 7885dc2a85..a7f7bd984a 100644 --- a/libr/bin/pdb/pdb.c +++ b/libr/bin/pdb/pdb.c @@ -554,17 +554,17 @@ static void finish_pdb_parse(R_PDB *pdb) { switch (i) { case 1: pdb_info_stream = (SPDBInfoStream *) r_list_iter_get (it); - // pdb_info_stream->free_(pdb_info_stream); + pdb_info_stream->free_(pdb_info_stream); free (pdb_info_stream); break; case 2: tpi_stream = (STpiStream *) r_list_iter_get (it); - // tpi_stream->free_(tpi_stream); + tpi_stream->free_(tpi_stream); free (tpi_stream); break; case 3: dbi_stream = (SDbiStream *) r_list_iter_get (it); - // dbi_stream->free_(dbi_stream); + dbi_stream->free_(dbi_stream); free (dbi_stream); break; default: @@ -573,7 +573,7 @@ static void finish_pdb_parse(R_PDB *pdb) { break; } pdb_stream = (R_PDB_STREAM *) r_list_iter_get (it); - // pdb_stream->free_(pdb_stream); + pdb_stream->free_(pdb_stream); free (pdb_stream); break; } @@ -583,7 +583,7 @@ static void finish_pdb_parse(R_PDB *pdb) { r_list_free (pdb->pdb_streams); // enf of free of pdb->pdb_streams -#if 0 +#if 1 // start of free pdb->pdb_streams2 it = r_list_iterator (pdb->pdb_streams2); while (r_list_iter_next (it)) { @@ -599,7 +599,7 @@ static void finish_pdb_parse(R_PDB *pdb) { // end of free pdb->streams2 free (pdb->stream_map); - free (pdb->buf); + r_buf_free (pdb->buf); // fclose(pdb->fp); // printf("finish_pdb_parse()\n"); @@ -798,7 +798,7 @@ void build_command_field(ELeafType lt, char **command_field) { switch (lt) { case eLF_STRUCTURE: case eLF_UNION: - *command_field = (char *) malloc (strlen ("pf") + 1); + *command_field = (char *) malloc (strlen ("pf.") + 1); if (!(*command_field)) { break; } diff --git a/libr/core/cmd_type.c b/libr/core/cmd_type.c index 9d13de85b7..979c8d7875 100644 --- a/libr/core/cmd_type.c +++ b/libr/core/cmd_type.c @@ -685,6 +685,7 @@ static int cmd_type(void *data, const char *input) { r_anal_type_del (core->anal, kv->key); } } + ls_free (l); free (tmp); } } else eprintf ("Invalid use of t- . See t-? for help.\n");