|
From: <sv...@va...> - 2012-01-13 21:41:24
|
Author: philippe
Date: 2012-01-13 21:36:46 +0000 (Fri, 13 Jan 2012)
New Revision: 12328
Log:
Valgrind gdbserver can open/close connections multiple times
=> avoid leak when re-computing the default vgdb prefix.
Similar change in vgdb.c
Modified:
trunk/coregrind/m_gdbserver/remote-utils.c
trunk/coregrind/vgdb.c
Modified: trunk/coregrind/m_gdbserver/remote-utils.c
===================================================================
--- trunk/coregrind/m_gdbserver/remote-utils.c 2012-01-11 11:34:23 UTC (rev 12327)
+++ trunk/coregrind/m_gdbserver/remote-utils.c 2012-01-13 21:36:46 UTC (rev 12328)
@@ -1079,13 +1079,13 @@
HChar *
VG_(vgdb_prefix_default)(void)
{
- const HChar *tmpdir;
- HChar *prefix;
+ static HChar *prefix;
- tmpdir = VG_(tmpdir)();
- prefix = malloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
- strcpy(prefix, tmpdir);
- strcat(prefix, "/vgdb-pipe");
-
+ if (prefix == NULL) {
+ const HChar *tmpdir = VG_(tmpdir)();
+ prefix = malloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
+ strcpy(prefix, tmpdir);
+ strcat(prefix, "/vgdb-pipe");
+ }
return prefix;
}
Modified: trunk/coregrind/vgdb.c
===================================================================
--- trunk/coregrind/vgdb.c 2012-01-11 11:34:23 UTC (rev 12327)
+++ trunk/coregrind/vgdb.c 2012-01-13 21:36:46 UTC (rev 12328)
@@ -181,25 +181,27 @@
const char *tmpdir;
tmpdir = getenv("TMPDIR");
- if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR;
- if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */
+ if (tmpdir == NULL || *tmpdir == '\0')
+ tmpdir = VG_TMPDIR;
+ if (tmpdir == NULL || *tmpdir == '\0')
+ tmpdir = "/tmp"; /* fallback */
return tmpdir;
}
-/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb
+/* Return the default path prefix for the named pipes (FIFOs) used by vgdb/gdb
to communicate with valgrind */
static
char *vgdb_prefix_default(void)
{
- const char *tmpdir;
- HChar *prefix;
-
- tmpdir = vgdb_tmpdir();
- prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
- strcpy(prefix, tmpdir);
- strcat(prefix, "/vgdb-pipe");
+ static HChar *prefix;
+ if (prefix == NULL) {
+ const char *tmpdir = vgdb_tmpdir();
+ prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1);
+ strcpy(prefix, tmpdir);
+ strcat(prefix, "/vgdb-pipe");
+ }
return prefix;
}
|