]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Valgrind gdbserver can open/close connections multiple times
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Fri, 13 Jan 2012 21:36:46 +0000 (21:36 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Fri, 13 Jan 2012 21:36:46 +0000 (21:36 +0000)
=> avoid leak when re-computing the default vgdb prefix.
Similar change in vgdb.c

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12328

coregrind/m_gdbserver/remote-utils.c
coregrind/vgdb.c

index c0062950b9f254cb2e34e820768aa6daeeca4554..145fc2420c11363d830519461064f817a7c2e4b4 100644 (file)
@@ -1079,13 +1079,13 @@ int decode_X_packet (char *from, int packet_len, CORE_ADDR *mem_addr_ptr,
 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;
 }
index 38adc1c4bdced662a6d0ba73b5708972a53b1695..d2f51820c99753baff19e5192d30464b02e8e9d6 100644 (file)
@@ -181,25 +181,27 @@ const char *vgdb_tmpdir(void)
    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;
 }