From ec49299cb54870105a4a90871e29dd79655ebe65 Mon Sep 17 00:00:00 2001 From: radare Date: Thu, 2 Apr 2020 16:40:09 +0200 Subject: [PATCH] Fix memory leak reported by coverity in mach0 (#16405) --- libr/bin/format/objc/mach0_classes.c | 6 ++---- libr/core/panels.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libr/bin/format/objc/mach0_classes.c b/libr/bin/format/objc/mach0_classes.c index 0c4f742658..0493ab2e58 100644 --- a/libr/bin/format/objc/mach0_classes.c +++ b/libr/bin/format/objc/mach0_classes.c @@ -182,7 +182,6 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { struct MACH0_(SIVar) i; mach0_ut r; ut32 offset, left, j; - char *name = NULL; int len; bool bigendian; @@ -295,6 +294,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { if (r > bf->size || r + left > bf->size) { goto error; } + char *name; if (bin->has_crypto) { name = strdup ("some_encrypted_data"); left = strlen (name) + 1; @@ -311,9 +311,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { } // XXX the field name shouldnt contain the class name field->name = r_str_newf ("%s::%s%s", klass->name, "(ivar)", name); - //field->name = name; // (ivar) - //name = NULL; - // R_FREE (name); + R_FREE (name); } r = va2pa (i.type, NULL, &left, bf); diff --git a/libr/core/panels.c b/libr/core/panels.c index a94146695f..315be51a07 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -371,7 +371,7 @@ static void __panels_layout_refresh(RCore *core); static void __panels_layout(RPanels *panels); static void __layout_default(RPanels *panels); static void __layout_equal_hor(RPanels *panels); -static void r_save_panels_layout_noname(RCore *core); +R_API void r_save_panels_layout(RCore *core, const char *_name); R_API bool r_load_panels_layout(RCore *core, const char *_name); static void __split_panel_vertical(RCore *core, RPanel *p, const char *name, const char *cmd); static void __split_panel_horizontal(RCore *core, RPanel *p, const char *name, const char *cmd); @@ -3317,7 +3317,7 @@ int __close_file_cb(void *user) { int __save_layout_cb(void *user) { RCore *core = (RCore *)user; - r_save_panels_layout_noname (core); + r_save_panels_layout (core, NULL); __set_mode (core, PANEL_MODE_DEFAULT); __clear_panels_menu (core); __get_cur_panel (core->panels)->view->refresh = true; @@ -5650,15 +5650,18 @@ char *__get_panels_config_file_from_dir (const char *file) { return ret; } -static void r_save_panels_layout_noname(RCore *core) { +R_API void r_save_panels_layout(RCore *core, const char *oname) { int i; if (!core->panels) { return; } - const char *name = __show_status_input (core, "Name for the layout: "); + const char *name = oname; if (R_STR_ISEMPTY (name)) { - (void)__show_status (core, "Name can't be empty!"); - return; + name = __show_status_input (core, "Name for the layout: "); + if (R_STR_ISEMPTY (name)) { + (void)__show_status (core, "Name can't be empty!"); + return; + } } char *config_path = __create_panels_config_path (name); RPanels *panels = core->panels;