system-linux: fix resource leak
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 5 Aug 2019 20:05:36 +0000 (22:05 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Mon, 5 Aug 2019 20:07:43 +0000 (22:07 +0200)
Fix cb leak in case invalid type is specified in system_if_clear_entries
Detected by Coverity in CID1431183

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
system-linux.c

index c406a3d5085fffdbba99b47b8d30f22bed68e90f..acfd40eaf4f780a8b23ee78bad88e9bc55a5c3e5 100644 (file)
@@ -985,7 +985,7 @@ static void
 system_if_clear_entries(struct device *dev, int type, int af)
 {
        struct clear_data clr;
-       struct nl_cb *cb = nl_cb_alloc(NL_CB_DEFAULT);
+       struct nl_cb *cb;
        struct rtmsg rtm = {
                .rtm_family = af,
                .rtm_flags = RTM_F_CLONED,
@@ -993,9 +993,6 @@ system_if_clear_entries(struct device *dev, int type, int af)
        int flags = NLM_F_DUMP;
        int pending = 1;
 
-       if (!cb)
-               return;
-
        clr.af = af;
        clr.dev = dev;
        clr.type = type;
@@ -1011,6 +1008,10 @@ system_if_clear_entries(struct device *dev, int type, int af)
                return;
        }
 
+       cb = nl_cb_alloc(NL_CB_DEFAULT);
+       if (!cb)
+               return;
+
        clr.msg = nlmsg_alloc_simple(type, flags);
        if (!clr.msg)
                goto out;