mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-08 21:09:49 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user