Skip to content

Commit

Permalink
Fix few low hanging memleak fruits
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Jan 21, 2025
1 parent 60befec commit 6a81e61
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
3 changes: 0 additions & 3 deletions libr/anal/vtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ R_API void r_anal_vtables_list(RAnal *anal, int rad) {

if (rad == 'j') {
PJ *pj = pj_new ();
if (!pj) {
return;
}
pj_a (pj);
r_list_foreach (vtables, vtableIter, table) {
pj_o (pj);
Expand Down
4 changes: 2 additions & 2 deletions libr/include/r_util/pj.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ typedef struct pj_t {
} PJ;

/* lifecycle */
R_API PJ *pj_new(void);
R_API PJ *pj_new_with_encoding(PJEncodingStr str_encoding, PJEncodingNum num_encoding);
R_API R_NONNULL PJ *pj_new(void);
R_API R_NONNULL PJ *pj_new_with_encoding(PJEncodingStr str_encoding, PJEncodingNum num_encoding);
R_API void pj_free(PJ *j);
R_API void pj_reset(PJ *j); // clear the pj contents, but keep the buffer allocated to re-use it
R_API char *pj_drain(PJ *j);
Expand Down
2 changes: 1 addition & 1 deletion libr/io/io_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ R_API bool r_io_map_setattr(RIOMap *map, ut32 type, ut32 flags) {
}

R_API char *r_io_map_getattr(RIOMap *map) {
RStrBuf *sb = r_strbuf_new ("");
ut32 maptype = map->meta & 0xffff;
ut32 mapflag = (map->meta > 16) & 0xffff;
if (maptype >= R_IO_MAP_META_TYPE_LAST) {
Expand All @@ -829,6 +828,7 @@ R_API char *r_io_map_getattr(RIOMap *map) {
if (mapflag >= R_IO_MAP_META_FLAG_LAST) {
return false;
}
RStrBuf *sb = r_strbuf_new ("");
r_strbuf_append (sb, metatypename[maptype]);
int i = 0;
for (i = 0; i < 16; i++) {
Expand Down
14 changes: 6 additions & 8 deletions libr/util/pj.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ static void pj_comma(PJ *j) {
j->is_key = false;
}

R_API PJ *pj_new(void) {
R_API R_NONNULL PJ *pj_new(void) {
PJ *j = R_NEW0 (PJ);
if (j) {
r_strbuf_init (&j->sb);
j->is_first = true;
j->comma = ",";
j->str_encoding = PJ_ENCODING_STR_DEFAULT;
j->num_encoding = PJ_ENCODING_NUM_DEFAULT;
}
r_strbuf_init (&j->sb);
j->is_first = true;
j->comma = ",";
j->str_encoding = PJ_ENCODING_STR_DEFAULT;
j->num_encoding = PJ_ENCODING_NUM_DEFAULT;
return j;
}

Expand Down

0 comments on commit 6a81e61

Please sign in to comment.