file: exec: properly free memory on error
authorYousong Zhou <yszhou4tech@gmail.com>
Mon, 21 Oct 2019 12:59:23 +0000 (12:59 +0000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 29 Oct 2019 08:26:18 +0000 (09:26 +0100)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
[fix whitespace]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
file.c

diff --git a/file.c b/file.c
index b1adcb7c431bc55a770dea3508bd4fcbacae5adc..4ed2e5cae2a5bb277a55dd371c17535caf76e6f1 100644 (file)
--- a/file.c
+++ b/file.c
@@ -823,13 +823,16 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr *sid,
        if (!c)
                return UBUS_STATUS_UNKNOWN_ERROR;
 
-       if (pipe(opipe) || pipe(epipe))
-               return rpc_errno_status();
+       if (pipe(opipe))
+               goto fail_opipe;
+
+       if (pipe(epipe))
+               goto fail_epipe;
 
        switch ((pid = fork()))
        {
        case -1:
-               return rpc_errno_status();
+               goto fail_fork;
 
        case 0:
                uloop_done();
@@ -921,6 +924,18 @@ rpc_file_exec_run(const char *cmd, const struct blob_attr *sid,
        }
 
        return UBUS_STATUS_OK;
+
+fail_fork:
+       close(epipe[0]);
+       close(epipe[1]);
+
+fail_epipe:
+       close(opipe[0]);
+       close(opipe[1]);
+
+fail_opipe:
+       free(c);
+       return rpc_errno_status();
 }
 
 static int