From: Rosen Penev Date: Sun, 4 Dec 2016 04:39:42 +0000 (-0800) Subject: procd: Fix memory leaks found by cppcheck X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4004b68fe57dd72197b8a00b0756cc7f978ad88a;p=oweals%2Fprocd.git procd: Fix memory leaks found by cppcheck Signed-off by: Rosen Penev --- diff --git a/initd/mkdev.c b/initd/mkdev.c index e6d3d0c..e826707 100644 --- a/initd/mkdev.c +++ b/initd/mkdev.c @@ -121,5 +121,6 @@ int mkdev(const char *name, int _mode) n_patterns = 1; find_devs(true); find_devs(false); + free(pattern); return chdir("/"); } diff --git a/service/instance.c b/service/instance.c index d75e1ab..8838049 100644 --- a/service/instance.c +++ b/service/instance.c @@ -263,6 +263,7 @@ instance_writepid(struct service_instance *in) if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) { ERROR("failed to write pidfile: %s: %d (%s)", in->pidfile, errno, strerror(errno)); + fclose(_pidfile); return 2; } if (fclose(_pidfile)) { diff --git a/trace/trace.c b/trace/trace.c index b0005b8..662010e 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -176,7 +176,7 @@ int main(int argc, char **argv, char **envp) if (child == 0) { char **_argv = calloc(argc + 1, sizeof(char *)); char **_envp; - char preload[] = "LD_PRELOAD=/lib/libpreload-trace.so"; + char *preload = "LD_PRELOAD=/lib/libpreload-trace.so"; int envc = 1; int ret; @@ -191,6 +191,9 @@ int main(int argc, char **argv, char **envp) ret = execve(_argv[0], _argv, envp); ERROR("failed to exec %s: %s\n", _argv[0], strerror(errno)); + + free(_argv); + free(_envp); return ret; }