From: Mark Wielaard Date: Sat, 25 May 2019 14:31:02 +0000 (+0200) Subject: Fix memory leak in launcher-linux.c X-Git-Tag: VALGRIND_3_16_0~281 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f15beea767892ae52ed1d92d789114685fb5dc82;p=thirdparty%2Fvalgrind.git Fix memory leak in launcher-linux.c When the clientname argument is not a full absolute path we reconstruct the full path using $PATH. This reconstructed full path would be leaked. This is small and insignificant. But valgrind should give a good example. So free the path again when we are done and allocated the memory. Also don't print the path twice in the debug output if we didn't need to construct a new different path for it. --- diff --git a/coregrind/launcher-linux.c b/coregrind/launcher-linux.c index 105d023a54..954a3fd8c7 100644 --- a/coregrind/launcher-linux.c +++ b/coregrind/launcher-linux.c @@ -144,28 +144,34 @@ static const char *select_platform(const char *clientname) } header; ssize_t n_bytes; const char *platform = NULL; + const char *client = clientname; VG_(debugLog)(2, "launcher", "selecting platform for '%s'\n", clientname); if (strchr(clientname, '/') == NULL) - clientname = find_client(clientname); + client = find_client(clientname); - VG_(debugLog)(2, "launcher", "selecting platform for '%s'\n", clientname); + if (client != clientname) + VG_(debugLog)(2, "launcher", "selecting platform for '%s'\n", client); - if ((fd = open(clientname, O_RDONLY)) < 0) + if ((fd = open(clientname, O_RDONLY)) < 0) { + return_null: + if (client != clientname) + free (client); return NULL; + } // barf("open(%s): %s", clientname, strerror(errno)); - VG_(debugLog)(2, "launcher", "opened '%s'\n", clientname); + VG_(debugLog)(2, "launcher", "opened '%s'\n", client); n_bytes = read(fd, header.c, sizeof(header)); close(fd); if (n_bytes < 2) { - return NULL; + goto return_null; } VG_(debugLog)(2, "launcher", "read %ld bytes from '%s'\n", - (long int)n_bytes, clientname); + (long int)n_bytes, client); if (header.c[0] == '#' && header.c[1] == '!') { int i = 2; @@ -322,6 +328,9 @@ static const char *select_platform(const char *clientname) VG_(debugLog)(2, "launcher", "selected platform '%s'\n", platform ? platform : "unknown"); + if (client != clientname) + free (client); + return platform; }