ref: 96b6f55ec834471414576f2ea761f0a29bd47cdc
parent: 2fb2774fcdd207a092b065faf10f081294c88f90
author: Jonas Kölker <jonaskoelker@yahoo.com>
date: Tue Oct 6 21:08:11 EDT 2015
Fix two memory leaks in GTK frontend. - The file selector for loading and saving gets a g_free(). - The handling of saving (menu_save_event) gets an sfree(). - It's also slightly restructured to prevent future errors. - menu_load_event was already structured to prevent this error. - The OLD_FILESEL code seems to not need a g_free().
--- a/gtk.c
+++ b/gtk.c
@@ -2098,8 +2098,9 @@
NULL);
if (gtk_dialog_run(GTK_DIALOG(filesel)) == GTK_RESPONSE_ACCEPT) {
- const char *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel));
+ char *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filesel));
filesel_name = dupstr(name);
+ g_free(name);
}
gtk_widget_destroy(filesel);
@@ -2149,15 +2150,14 @@
" file \"%.*s\"?",
FILENAME_MAX, name);
if (!message_box(fe->window, "Question", buf, TRUE, MB_YESNO))
- return;
+ goto free_and_return;
}
fp = fopen(name, "w");
- sfree(name);
if (!fp) {
error_box(fe->window, "Unable to open save file");
- return;
+ goto free_and_return;
}
{
@@ -2171,10 +2171,11 @@
sprintf(boxmsg, "Error writing save file: %.400s",
strerror(errno));
error_box(fe->window, boxmsg);
- return;
+ goto free_and_return;
}
}
-
+ free_and_return:
+ sfree(name);
}
}