[OpenWrt-Devel,rpcd,1/4] plugin: exec: properly free memory on parse error
diff mbox series

Message ID 20191020112608.129703-1-yszhou4tech@gmail.com
State Superseded
Headers show
Series
  • [OpenWrt-Devel,rpcd,1/4] plugin: exec: properly free memory on parse error
Related show

Commit Message

Yousong Zhou Oct. 20, 2019, 11:26 a.m. UTC
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
 plugin.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/plugin.c b/plugin.c
index 3740622..d3526aa 100644
--- a/plugin.c
+++ b/plugin.c
@@ -321,11 +321,16 @@  rpc_plugin_parse_exec(const char *name, int fd)
 
 	obj_type = calloc(1, sizeof(*obj_type));
 
-	if (!obj_type)
+	if (!obj_type) {
+		free(obj);
 		return NULL;
+	}
 
-	if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0)
+	if (asprintf((char **)&obj_type->name, "luci-rpc-plugin-%s", name) < 0) {
+		free(obj);
+		free(obj_type);
 		return NULL;
+	}
 
 	obj_type->methods = methods;
 	obj_type->n_methods = n_method;