[LEDE-DEV] [PATCH] procd: Fix memory leaks found by cppcheck
Rosen Penev
rosenp at gmail.com
Sat Dec 3 20:39:42 PST 2016
Signed-off by: Rosen Penev <rosenp at gmail.com>
---
initd/mkdev.c | 1 +
service/instance.c | 1 +
trace/trace.c | 5 ++++-
3 files changed, 6 insertions(+), 1 deletion(-)
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;
}
--
2.9.3
More information about the Lede-dev
mailing list