net/nfp: fix memory leak
authorAlejandro Lucero <alejandro.lucero@netronome.com>
Mon, 8 Apr 2019 10:19:29 +0000 (11:19 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 12 Apr 2019 09:02:02 +0000 (11:02 +0200)
If errors, release the allocated structure.

Coverity issue: 277222
Fixes: c7e9729da6b5 ("net/nfp: support CPP")
Cc: stable@dpdk.org
Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
drivers/net/nfp/nfpcore/nfp_cpp_pcie_ops.c

index 93ee310..33baa98 100644 (file)
@@ -865,24 +865,24 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev)
            cpp->driver_lock_needed) {
                ret = nfp_acquire_process_lock(desc);
                if (ret)
-                       return -1;
+                       goto error;
        }
 
        /* Just support for one secondary process */
        if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
                ret = nfp_acquire_secondary_process_lock(desc);
                if (ret)
-                       return -1;
+                       goto error;
        }
 
        if (nfp6000_set_model(dev, cpp) < 0)
-               return -1;
+               goto error;
        if (nfp6000_set_interface(dev, cpp) < 0)
-               return -1;
+               goto error;
        if (nfp6000_set_serial(dev, cpp) < 0)
-               return -1;
+               goto error;
        if (nfp6000_set_barsz(dev, desc) < 0)
-               return -1;
+               goto error;
 
        desc->cfg = (char *)dev->mem_resource[0].addr;
 
@@ -890,7 +890,11 @@ nfp6000_init(struct nfp_cpp *cpp, struct rte_pci_device *dev)
 
        nfp_cpp_priv_set(cpp, desc);
 
-       return ret;
+       return 0;
+
+error:
+       free(desc);
+       return -1;
 }
 
 static void