diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2018-11-26 09:24:02 +0100 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2018-11-26 09:26:42 +0100 |
commit | 85de9def885fee6335a526bc2b3b733e1f6b7014 (patch) | |
tree | af36cf10b7d76610013dbecea8236c0db2c27f29 | |
parent | 4b83102da60bf26b455ac8425a1f5e338ea01f8a (diff) |
interface: fix memory leak on error in __interface_add()
Detected by Coverity in cid 1441495
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r-- | interface.c | 9 |
1 files changed, 8 insertions, 1 deletions
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); |