diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2012-09-13 10:46:09 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-09-13 10:46:09 -0700 |
commit | c74f58786d0a031a184b0933ddd19f7c48031bcc (patch) | |
tree | 11a3579605a5ab21ed41ebbd5117605f86b6c23c | |
parent | 5dbf10a6d679e38b3e0a407bb6659f9bb4b8a6ce (diff) | |
download | subsurface-c74f58786d0a031a184b0933ddd19f7c48031bcc.tar.gz |
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>
-rw-r--r-- | gtk-gui.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -305,6 +305,9 @@ static void file_close(GtkWidget *w, gpointer data) if (unsaved_changes()) if (ask_save_changes() == FALSE) return; + + if (existing_filename) + free(existing_filename); existing_filename = NULL; /* 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, * update existing_filename */ - if (strcmp(current_default, existing_filename) == 0) - existing_filename = (char *)new_default; + if (existing_filename) { + if (strcmp(current_default, existing_filename) == 0) { + free(existing_filename); + existing_filename = strdup(new_default); + } + } if (strcmp(current_default, new_default)) { subsurface_set_conf("default_filename", PREF_STRING, new_default); @@ -1091,6 +1098,8 @@ void exit_ui(void) subsurface_close_conf(); if (default_filename) free((char *)default_filename); + if (existing_filename) + free(existing_filename); } typedef struct { |