pci: fix potential mem leaks
authorDavid Marchand <david.marchand@6wind.com>
Fri, 9 May 2014 13:15:53 +0000 (15:15 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Tue, 13 May 2014 11:18:17 +0000 (13:18 +0200)
Looking at bsd implementation, we can see that there are some potential mem
leaks in linux implementation. Fix them.

Signed-off-by: David Marchand <david.marchand@6wind.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
lib/librte_eal/linuxapp/eal/eal_pci.c

index 9538efe..99e07d2 100644 (file)
@@ -649,11 +649,13 @@ pci_uio_map_resource(struct rte_pci_device *dev)
        memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
 
        /* collect info about device mappings */
-       if ((nb_maps = pci_uio_get_mappings(dirname, uio_res->maps,
-                       sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
-                       < 0)
+       nb_maps = pci_uio_get_mappings(dirname, uio_res->maps,
+                                      RTE_DIM(uio_res->maps));
+       if (nb_maps < 0) {
+               rte_free(uio_res);
                return (nb_maps);
+       }
+
        uio_res->nb_maps = nb_maps;
 
        /* Map all BARs */
@@ -678,6 +680,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
                                        (mapaddr = pci_map_resource(dev,
                                        NULL, devname, (off_t)offset,
                                        (size_t)maps[j].size)) == NULL) {
+                               rte_free(uio_res);
                                return (-1);
                        }