procd: Fix memory leaks found by cppcheck
authorRosen Penev <rosenp@gmail.com>
Sun, 4 Dec 2016 04:39:42 +0000 (20:39 -0800)
committerFelix Fietkau <nbd@nbd.name>
Mon, 5 Dec 2016 17:19:10 +0000 (18:19 +0100)
Signed-off by: Rosen Penev <rosenp@gmail.com>

initd/mkdev.c
service/instance.c
trace/trace.c

index e6d3d0c2920414847617b38ed92a18a0214b1d51..e82670723a6084682b85f396359c077502227ea2 100644 (file)
@@ -121,5 +121,6 @@ int mkdev(const char *name, int _mode)
        n_patterns = 1;
        find_devs(true);
        find_devs(false);
+       free(pattern);
        return chdir("/");
 }
index d75e1abdce6071bb4bf99a13904ad7e8f33c8045..88380499d56f34ccf07f063c9f63e9e3a6a19ebf 100644 (file)
@@ -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)) {
index b0005b8a8178dc4a738dd9c475d30ad7a731f43f..662010e339ea224d04d9a5e701b1eeed5855934f 100644 (file)
@@ -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;
        }