From: Philippe Waroquiers Date: Fri, 13 Jan 2012 21:36:46 +0000 (+0000) Subject: Valgrind gdbserver can open/close connections multiple times X-Git-Tag: svn/VALGRIND_3_8_0~525 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1910a81caaeadd386fa772d271250596bf677c8;p=thirdparty%2Fvalgrind.git Valgrind gdbserver can open/close connections multiple times => avoid leak when re-computing the default vgdb prefix. Similar change in vgdb.c git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12328 --- diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c index c0062950b9..145fc2420c 100644 --- a/coregrind/m_gdbserver/remote-utils.c +++ b/coregrind/m_gdbserver/remote-utils.c @@ -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; } diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 38adc1c4bd..d2f51820c9 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -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; }