From 8990aac31de42f6eeef1a4b5594d63df802882de Mon Sep 17 00:00:00 2001 From: David Marchand Date: Fri, 9 May 2014 15:15:53 +0200 Subject: [PATCH] pci: fix potential mem leaks Looking at bsd implementation, we can see that there are some potential mem leaks in linux implementation. Fix them. Signed-off-by: David Marchand Acked-by: Anatoly Burakov Acked-by: Neil Horman --- lib/librte_eal/linuxapp/eal/eal_pci.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c index 9538efee0e..99e07d2482 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -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); } -- 2.20.1