From 5c3daf901377d84c916f26c62d8eec41b573c0c3 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 3 Nov 2013 15:00:40 +0000 Subject: fix memory leak in error path (coverity 1109889) --- gtk/scaffolding.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/gtk/scaffolding.c b/gtk/scaffolding.c index 3d86975cc..0589b1e0f 100644 --- a/gtk/scaffolding.c +++ b/gtk/scaffolding.c @@ -1854,7 +1854,6 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) g = malloc(sizeof(*g)); if (g == NULL) { - warn_user("NoMemory", 0); return NULL; } @@ -1883,7 +1882,6 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) g->search = malloc(sizeof(struct gtk_search)); if (g->search == NULL) { - warn_user("NoMemory", 0); free(g); return NULL; } @@ -1901,23 +1899,20 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel) #undef GET_WIDGET + /* allocate buttons */ for (i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) { - g->buttons[i] = malloc(sizeof(struct nsgtk_button_connect)); + g->buttons[i] = calloc(1, sizeof(struct nsgtk_button_connect)); if (g->buttons[i] == NULL) { - warn_user("NoMemory", 0); + for (i-- ; i >= BACK_BUTTON; i--) { + free(g->buttons[i]); + } + free(g); return NULL; } - g->buttons[i]->button = NULL; g->buttons[i]->location = -1; g->buttons[i]->sensitivity = true; - g->buttons[i]->main = NULL; - g->buttons[i]->rclick = NULL; - g->buttons[i]->popup = NULL; - g->buttons[i]->mhandler = NULL; - g->buttons[i]->bhandler = NULL; - g->buttons[i]->dataplus = NULL; - g->buttons[i]->dataminus = NULL; } + /* here custom toolbutton adding code */ g->offset = 0; g->toolbarmem = 0; -- cgit v1.2.3