diff options
author | Mattias Andrée <maandree@kth.se> | 2016-08-05 14:13:22 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-08-05 14:13:22 +0200 |
commit | 272464fac03859636383f1d9eeafe8af56470ab1 (patch) | |
tree | 47c0b05ecc83866c03e3af5da5a5edb66ed9de88 /src/servers | |
parent | Fix reading of uninitialised value (diff) | |
download | coopgammad-272464fac03859636383f1d9eeafe8af56470ab1.tar.gz coopgammad-272464fac03859636383f1d9eeafe8af56470ab1.tar.bz2 coopgammad-272464fac03859636383f1d9eeafe8af56470ab1.tar.xz |
Fix bugs
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/servers')
-rw-r--r-- | src/servers/kernel.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/servers/kernel.c b/src/servers/kernel.c index de64e04..19af912 100644 --- a/src/servers/kernel.c +++ b/src/servers/kernel.c @@ -197,6 +197,7 @@ static int is_pidfile_reusable(const char* restrict pidpath, const char* restric sprintf(temp, "%llu\n", (unsigned long long)pid); if (strcmp(content, temp)) goto bad; + free(content); /* Validate PID */ #if defined(HAVE_LINUX_PROCFS) @@ -211,7 +212,8 @@ static int is_pidfile_reusable(const char* restrict pidpath, const char* restric for (end = (p = content) + n; p != end; p = strchr(p, '\0') + 1) if (!strcmp(p, token)) - return 0; + return free(content), 0; + free(content); #else if ((kill(pid, 0) == 0) || (errno == EINVAL)) return 0; @@ -250,8 +252,20 @@ int create_pidfile(char* pidpath) if (token == NULL) return -1; sprintf(token, "COOPGAMMAD_PIDFILE_TOKEN=%s", pidpath); +#if !defined(USE_VALGRIND) if (putenv(token)) - goto fail; + goto putenv_fail; + /* `token` must not be free! */ +#else + { + static char static_token[sizeof("COOPGAMMAD_PIDFILE_TOKEN=") + PATH_MAX]; + if (strlen(pidpath) > PATH_MAX) + abort(); + strcpy(static_token, token); + if (putenv(static_token)) + goto fail; + } +#endif /* Create PID file's directory. */ for (p = pidpath; *p == '/'; p++); @@ -294,14 +308,24 @@ int create_pidfile(char* pidpath) goto fail; /* Done */ +#if defined(USE_VALGRIND) free(token); +#endif if (close(fd) < 0) if (errno != EINTR) return -1; return 0; +#if !defined(USE_VALGRIND) + putenv_fail: + saved_errno = errno; + free(token); + errno = saved_errno; +#endif fail: saved_errno = errno; +#if defined(USE_VALGRIND) free(token); +#endif if (fd >= 0) { close(fd); |