From 9630bf353e2ca03bdce5d7ce00f184c898ba40cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Mayer?= Date: Thu, 1 Aug 2002 03:15:29 +0000 Subject: [PATCH] Fix a few more memleaks found by valgrind (all deriving from the get_persconffile_path mess). svn path=/trunk/; revision=5927 --- AUTHORS | 1 + gtk/main.c | 9 +++++++-- gtk/prefs_dlg.c | 5 +++-- prefs.c | 12 +++++++----- prefs.h | 6 +++--- tethereal.c | 6 ++++-- 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0e6f386e4b..3c3355007e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -93,6 +93,7 @@ Joerg Mayer { Clean up #includes Mark last packet of TFTP transfer as such in the Info column Dissect both the BOOTP server and client ports as bootp/DHCP + Fix some small memleaks found by valgrind } Martin Maciaszek { diff --git a/gtk/main.c b/gtk/main.c index 2fccf22dde..fdebf8a4ca 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.255 2002/07/07 22:14:03 guy Exp $ + * $Id: main.c,v 1.256 2002/08/01 03:15:29 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -1213,7 +1213,7 @@ main(int argc, char *argv[]) #endif char *gpf_path, *cf_path, *df_path; - const char *pf_path; + char *pf_path; int gpf_open_errno, pf_open_errno, cf_open_errno, df_open_errno; int err; #ifdef HAVE_LIBPCAP @@ -1953,6 +1953,8 @@ main(int argc, char *argv[]) simple_dialog(ESD_TYPE_WARN, NULL, "Could not open your preferences file\n\"%s\": %s.", pf_path, strerror(pf_open_errno)); + g_free(pf_path); + pf_path = NULL; } /* If the user's capture filter file exists but we failed to open it, @@ -2060,6 +2062,9 @@ main(int argc, char *argv[]) if (prefs_write_needed) { write_prefs(&pf_path); } + } else { + /* Ignore errors silently */ + g_free(pf_path); } epan_cleanup(); diff --git a/gtk/prefs_dlg.c b/gtk/prefs_dlg.c index fe3773174e..90b9b76067 100644 --- a/gtk/prefs_dlg.c +++ b/gtk/prefs_dlg.c @@ -1,7 +1,7 @@ /* prefs_dlg.c * Routines for handling preferences * - * $Id: prefs_dlg.c,v 1.49 2002/07/17 00:22:30 guy Exp $ + * $Id: prefs_dlg.c,v 1.50 2002/08/01 03:15:29 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -914,7 +914,7 @@ prefs_main_save_cb(GtkWidget *save_bt _U_, gpointer parent_w) gboolean must_redissect = FALSE; int err; char *pf_dir_path; - const char *pf_path; + char *pf_path; /* Fetch the preferences (i.e., make sure all the values set in all of the preferences panes have been copied to "prefs" and the registered @@ -950,6 +950,7 @@ prefs_main_save_cb(GtkWidget *save_bt _U_, gpointer parent_w) simple_dialog(ESD_TYPE_WARN, NULL, "Can't open preferences file\n\"%s\": %s.", pf_path, strerror(err)); + g_free(pf_path); } } diff --git a/prefs.c b/prefs.c index d921e0ea6e..78b594518f 100644 --- a/prefs.c +++ b/prefs.c @@ -1,7 +1,7 @@ /* prefs.c * Routines for handling preferences * - * $Id: prefs.c,v 1.86 2002/06/16 00:58:37 guy Exp $ + * $Id: prefs.c,v 1.87 2002/08/01 03:15:25 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -721,10 +721,10 @@ static void read_prefs_file(const char *pf_path, FILE *pf); return NULL. */ e_prefs * read_prefs(int *gpf_errno_return, char **gpf_path_return, - int *pf_errno_return, const char **pf_path_return) + int *pf_errno_return, char **pf_path_return) { int i; - const char *pf_path; + char *pf_path; FILE *pf; fmt_data *cfmt; gchar *col_fmt[] = {"No.", "%m", "Time", "%t", @@ -876,6 +876,8 @@ read_prefs(int *gpf_errno_return, char **gpf_path_return, /* We succeeded in opening it; read it. */ read_prefs_file(pf_path, pf); fclose(pf); + g_free(pf_path); + pf_path = NULL; } else { /* We failed to open it. If we failed for some reason other than "it doesn't exist", return the errno and the pathname, so our @@ -1662,9 +1664,9 @@ write_module_prefs(gpointer data, gpointer user_data) If we got an error, stuff a pointer to the path of the preferences file into "*pf_path_return", and return the errno. */ int -write_prefs(const char **pf_path_return) +write_prefs(char **pf_path_return) { - const char *pf_path; + char *pf_path; FILE *pf; GList *clp, *col_l; fmt_data *cfmt; diff --git a/prefs.h b/prefs.h index 474d134909..135ce0ca19 100644 --- a/prefs.h +++ b/prefs.h @@ -1,7 +1,7 @@ /* prefs.h * Definitions for preference handling routines * - * $Id: prefs.h,v 1.38 2002/05/11 18:58:02 guy Exp $ + * $Id: prefs.h,v 1.39 2002/08/01 03:15:25 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -202,13 +202,13 @@ extern void prefs_register_modules(void); the user's preferences file, stuff the errno into "*pf_errno_return" and a pointer to the path of the file into "*pf_path_return", and return NULL. */ -extern e_prefs *read_prefs(int *, char **, int *, const char **); +extern e_prefs *read_prefs(int *, char **, int *, char **); /* Write out "prefs" to the user's preferences file, and return 0. If we got an error, stuff a pointer to the path of the preferences file into "*pf_path_return", and return the errno. */ -extern int write_prefs(const char **); +extern int write_prefs(char **); /* Copy a set of preferences. */ extern void copy_prefs(e_prefs *dest, e_prefs *src); diff --git a/tethereal.c b/tethereal.c index f34cb7d990..df53d4dfe5 100644 --- a/tethereal.c +++ b/tethereal.c @@ -1,6 +1,6 @@ /* tethereal.c * - * $Id: tethereal.c,v 1.149 2002/07/17 00:22:12 guy Exp $ + * $Id: tethereal.c,v 1.150 2002/08/01 03:15:26 jmayer Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -313,7 +313,7 @@ main(int argc, char *argv[]) #endif char *gpf_path; - const char *pf_path; + char *pf_path; int gpf_open_errno, pf_open_errno; int err; #ifdef HAVE_LIBPCAP @@ -377,6 +377,8 @@ main(int argc, char *argv[]) if (pf_path != NULL) { fprintf(stderr, "Can't open your preferences file \"%s\": %s.\n", pf_path, strerror(pf_open_errno)); + g_free(pf_path); + pf_path = NULL; } /* Set the name resolution code's flags from the preferences. */