summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2019-10-21 12:59:23 +0000
committerJo-Philipp Wich <jo@mein.io>2019-10-29 09:26:18 +0100
commit90e40bd3d5b6d164be4c1f3583a13dc2f34d6563 (patch)
tree5ae85d6079f18d7bf3d4ffa15caaa6ef0c491e67
parent9ecfada16d7ad5ae942e6c0e65e1b9d7e89e21df (diff)
downloadrpcd-90e40bd3d5b6d164be4c1f3583a13dc2f34d6563.tar.gz
file: exec: properly free memory on error
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> [fix whitespace] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--file.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/file.c b/file.c
index b1adcb7..4ed2e5c 100644
--- 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