From 85de9def885fee6335a526bc2b3b733e1f6b7014 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Mon, 26 Nov 2018 09:24:02 +0100 Subject: [PATCH] interface: fix memory leak on error in __interface_add() Detected by Coverity in cid 1441495 Signed-off-by: Hans Dedecker --- interface.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/interface.c b/interface.c index 4cefe64..44f7a87 100644 --- a/interface.c +++ b/interface.c @@ -892,7 +892,7 @@ static bool __interface_add(struct interface *iface, struct blob_attr *config, b { struct blob_attr *tb[IFACE_ATTR_MAX]; struct blob_attr *cur; - char *name = iface->dynamic ? strdup(iface->name) : NULL; + char *name = NULL; blobmsg_parse(iface_attrs, IFACE_ATTR_MAX, tb, blob_data(config), blob_len(config)); @@ -908,6 +908,13 @@ static bool __interface_add(struct interface *iface, struct blob_attr *config, b iface->ifname = blobmsg_data(cur); } + if (iface->dynamic) { + name = strdup(iface->name); + + if (!name) + return false; + } + iface->config = config; vlist_add(&interfaces, &iface->node, iface->name); -- 2.30.2