[OpenWrt-Devel] [PATCH rpcd v2 5/6] file: exec: properly free memory on error

Yousong Zhou yszhou4tech at gmail.com
Mon Oct 21 08:59:23 EDT 2019


Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
 file.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/file.c b/file.c
index b1adcb7..47fcd9a 100644
--- a/file.c
+++ b/file.c
@@ -823,13 +823,15 @@ 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 +923,16 @@ 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

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list