Ethereal-dev: [Ethereal-dev] get_persconffile_path mess (more memleak fixes)
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Tue, 30 Jul 2002 08:12:42 +0200
OK, some more memleaks found by valgrind fixed. Nothing serious, but it is a clear indication that allocating a buffer in a function and leaving the task of freeing to the calling function (or the function calling the calling function) simply doesn't work. Unfortunately, I havn't come up with a better idea either, so I'll just attach the fixes. Please check before applying. Ciao Jörg -- Joerg Mayer <jmayer@xxxxxxxxx> I found out that "pro" means "instead of" (as in proconsul). Now I know what proactive means.
Changelog: <jmayer@xxxxxxxxx>
prefs.c, prefs.h, tethereal.c, gtk/main.c, gtk/prefs_dlg.c:
Fix a few more memleaks found by valgrind (all deriving
from the get_persconffile_path mess).
Index: ethereal/prefs.c
===================================================================
RCS file: /cvsroot/ethereal/prefs.c,v
retrieving revision 1.86
diff -u -r1.86 prefs.c
--- prefs.c 2002/06/16 00:58:37 1.86
+++ prefs.c 2002/07/30 05:53:40
@@ -721,7 +721,7 @@
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;
@@ -876,6 +876,8 @@
/* 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,7 +1664,7 @@
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;
FILE *pf;
Index: ethereal/prefs.h
===================================================================
RCS file: /cvsroot/ethereal/prefs.h,v
retrieving revision 1.38
diff -u -r1.38 prefs.h
--- prefs.h 2002/05/11 18:58:02 1.38
+++ prefs.h 2002/07/30 05:53:40
@@ -202,13 +202,13 @@
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);
Index: ethereal/tethereal.c
===================================================================
RCS file: /cvsroot/ethereal/tethereal.c,v
retrieving revision 1.149
diff -u -r1.149 tethereal.c
--- tethereal.c 2002/07/17 00:22:12 1.149
+++ tethereal.c 2002/07/30 05:53:41
@@ -313,7 +313,7 @@
#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 @@
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. */
Index: ethereal/gtk/main.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/main.c,v
retrieving revision 1.255
diff -u -r1.255 main.c
--- main.c 2002/07/07 22:14:03 1.255
+++ main.c 2002/07/30 05:53:42
@@ -1213,7 +1213,7 @@
#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 @@
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 @@
if (prefs_write_needed) {
write_prefs(&pf_path);
}
+ } else {
+ /* Ignore errors silently */
+ g_free(pf_path);
}
epan_cleanup();
Index: ethereal/gtk/prefs_dlg.c
===================================================================
RCS file: /cvsroot/ethereal/gtk/prefs_dlg.c,v
retrieving revision 1.49
diff -u -r1.49 prefs_dlg.c
--- prefs_dlg.c 2002/07/17 00:22:30 1.49
+++ prefs_dlg.c 2002/07/30 05:53:43
@@ -914,7 +914,7 @@
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 @@
simple_dialog(ESD_TYPE_WARN, NULL,
"Can't open preferences file\n\"%s\": %s.", pf_path,
strerror(err));
+ g_free(pf_path);
}
}
- Prev by Date: [Ethereal-dev] bug in packet-dcerpc-epm.c
- Next by Date: Re: [Ethereal-dev] PATCH: netbios address type for kerberos
- Previous by thread: [Ethereal-dev] bug in packet-dcerpc-epm.c
- Next by thread: [Ethereal-dev] 802.11 compute FCS patch
- Index(es):





