On Thu, Jun 25, 2015 at 5:19 AM, Tetsuya Mukawa <mukawa at igel.co.jp> wrote:

> From: "Tetsuya.Mukawa" <mukawa at igel.co.jp>
>
> This patch fixes following memory leaks.
> - When open() is failed, uio_res and fds won't be freed in
>   pci_uio_map_resource().
> - When pci_map_resource() is failed but path is allocated correctly,
>   path and fds won't be freed in pci_uio_map_recource().
> - When pci_uio_unmap() is called, path should be freed.
>
> Also, fixes below.
> - When pci_map_resource() is failed, mapaddr will be MAP_FAILED.
>   In this case, pci_map_addr should not be incremented in
>   pci_uio_map_resource().
> - To shrink code, move close().
> - Remove fail variable.
>
> Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51
> ++++++++++++++++++++-----------
>  2 files changed, 44 insertions(+), 21 deletions(-)
>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c
> b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 8e24fd1..b071f07 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) ==
> NULL) {
>                 RTE_LOG(ERR, EAL,
>                         "%s(): cannot store uio mmap details\n", __func__);
> -               return -1;
> +               goto close_fd;
>         }
>
>         snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
> @@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>                     (mapaddr = pci_map_resource(NULL, devname,
> (off_t)offset,
>                                                 (size_t)maps[j].size)
>                     ) == NULL) {
> -                       rte_free(uio_res);
> -                       return -1;
> +                       goto free_uio_res;
>                 }
>
>                 maps[j].addr = mapaddr;
> @@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)
>         TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
>
>         return 0;
> +
> +free_uio_res:
> +       rte_free(uio_res);
> +close_fd:
> +       close(dev->intr_handle.fd);
> +       dev->intr_handle.fd = -1;
> +       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> +
> +       return -1;
>  }
>
>
Thinking about it, when something fails, don't you need to unmap pci
resources in uio_res->maps before freeing ?


-- 
David Marchand

Reply via email to