diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/coopgammad.c | 19 | ||||
-rw-r--r-- | src/servers/kernel.c | 28 | ||||
-rw-r--r-- | src/state.c | 1 |
3 files changed, 37 insertions, 11 deletions
diff --git a/src/coopgammad.c b/src/coopgammad.c index 83352e0..1276189 100644 --- a/src/coopgammad.c +++ b/src/coopgammad.c @@ -419,14 +419,13 @@ static enum init_status initialise(int foreground, int keep_stderr, int query) static void destroy(int full) { if (full) - disconnect_all(); - - if (full) - close_socket(socketpath); - - if (full && (outputs != NULL)) - restore_gamma(); - + { + disconnect_all(); + close_socket(socketpath); + free(argv0_real); + if (outputs != NULL) + restore_gamma(); + } state_destroy(); free(socketpath); if (full && (pidpath != NULL)) @@ -618,7 +617,11 @@ static char* reexecute(void) destroy(0); +#if !defined(USE_VALGRIND) execlp(argv0_real ? argv0_real : argv0, argv0, "- ", statefile, NULL); +#else + execlp("valgrind", "valgrind", "--leak-check=full", argv0_real ? argv0_real : argv0, "- ", statefile, NULL); +#endif saved_errno = errno; free(argv0_real), argv0_real = NULL; errno = saved_errno; 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); diff --git a/src/state.c b/src/state.c index c8cb1d9..d840ccb 100644 --- a/src/state.c +++ b/src/state.c @@ -172,7 +172,6 @@ void state_destroy(void) free(partitions); libgamma_site_destroy(&site); - free(argv0_real); free(sitename); } |