|
From: <sv...@va...> - 2005-06-19 15:35:04
|
Author: njn
Date: 2005-06-19 16:34:59 +0100 (Sun, 19 Jun 2005)
New Revision: 3947
Log:
Fixed a bug in .valgrindrc reading I introduced recently -- freeing memor=
y
I should not have.
Added a regression test for it.
MERGE TO 2.4 REPOSITORY
Modified:
trunk/coregrind/m_main.c
Modified: trunk/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_main.c 2005-06-19 05:43:21 UTC (rev 3946)
+++ trunk/coregrind/m_main.c 2005-06-19 15:34:59 UTC (rev 3947)
@@ -413,6 +413,8 @@
/*=3D=3D=3D Command line setup =
=3D=3D=3D*/
/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D*/
=20
+// Note that we deliberately don't free the malloc'd memory. See commen=
t
+// at call site.
static char* get_file_clo(char* dir)
{
# define FLEN 512
@@ -454,7 +456,10 @@
return n;
}
=20
-/* add args out of environment, skipping multiple spaces and -- args */
+// Add args out of environment, skipping multiple spaces and "--" args.
+// We split 's' into multiple strings by replacing whitespace with nuls,
+// eg. "--aa --bb --cc" --> "--aa\0--bb\0--cc". And for each new string
+// carved out of 's', we put a pointer to it in 'to'.
static char** copy_args( char* s, char** to )
{
if (s) {
@@ -466,7 +471,7 @@
if ( !*cp ) break;
*to++ =3D cp;
while ( !VG_(isspace)(*cp) && *cp ) cp++;
- if ( *cp ) *cp++ =3D '\0'; // terminate if necessary
+ if ( *cp ) *cp++ =3D '\0'; // terminate if not the l=
ast
if (VG_STREQ(to[-1], "--")) to--; // undo any '--' arg
}
}
@@ -480,6 +485,8 @@
int vg_argc0 =3D *vg_argc_inout;
char** vg_argv0 =3D *vg_argv_inout;
=20
+ // get_file_clo() allocates the return value with malloc(). We do no=
t
+ // free f1_clo and f2_clo as they get put into vg_argv[] which must p=
ersist.
char* env_clo =3D getenv(VALGRINDOPTS);
char* f1_clo =3D get_file_clo( getenv("HOME") );
char* f2_clo =3D get_file_clo(".");
@@ -518,10 +525,6 @@
to =3D copy_args(env_clo, to);
to =3D copy_args(f2_clo, to);
=20
- // Free memory
- free(f1_clo);
- free(f2_clo);
-
/* copy original arguments, stopping at command or -- */
while (*from) {
if (**from !=3D '-')
|
|
From: Nicholas N. <nj...@cs...> - 2005-06-19 15:41:58
|
On Sun, 19 Jun 2005 sv...@va... wrote: > Log: > Fixed a bug in .valgrindrc reading I introduced recently -- freeing memory > I should not have. > > Added a regression test for it. Whoops, no I didn't. Nick |