mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix memory leaks and one potential NULL dereference
Always make sure to clear the memory allocated at the "existing_filename" pointer when setting it to a new address or NULL. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Lifted these changes from a larger commit. The other changes I'll reimplement in the next commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5dbf10a6d6
commit
c74f58786d
1 changed files with 11 additions and 2 deletions
13
gtk-gui.c
13
gtk-gui.c
|
@ -305,6 +305,9 @@ static void file_close(GtkWidget *w, gpointer data)
|
||||||
if (unsaved_changes())
|
if (unsaved_changes())
|
||||||
if (ask_save_changes() == FALSE)
|
if (ask_save_changes() == FALSE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (existing_filename)
|
||||||
|
free(existing_filename);
|
||||||
existing_filename = NULL;
|
existing_filename = NULL;
|
||||||
|
|
||||||
/* free the dives and trips */
|
/* free the dives and trips */
|
||||||
|
@ -682,8 +685,12 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
|
||||||
|
|
||||||
/* if we opened the default file and are changing its name,
|
/* if we opened the default file and are changing its name,
|
||||||
* update existing_filename */
|
* update existing_filename */
|
||||||
if (strcmp(current_default, existing_filename) == 0)
|
if (existing_filename) {
|
||||||
existing_filename = (char *)new_default;
|
if (strcmp(current_default, existing_filename) == 0) {
|
||||||
|
free(existing_filename);
|
||||||
|
existing_filename = strdup(new_default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(current_default, new_default)) {
|
if (strcmp(current_default, new_default)) {
|
||||||
subsurface_set_conf("default_filename", PREF_STRING, new_default);
|
subsurface_set_conf("default_filename", PREF_STRING, new_default);
|
||||||
|
@ -1091,6 +1098,8 @@ void exit_ui(void)
|
||||||
subsurface_close_conf();
|
subsurface_close_conf();
|
||||||
if (default_filename)
|
if (default_filename)
|
||||||
free((char *)default_filename);
|
free((char *)default_filename);
|
||||||
|
if (existing_filename)
|
||||||
|
free(existing_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue