From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by dpdk.org (Postfix) with ESMTP id DDEA26A87 for ; Thu, 12 Mar 2015 11:18:23 +0100 (CET) Received: by pdev10 with SMTP id v10so19090571pde.0 for ; Thu, 12 Mar 2015 03:18:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Xj1YzkNURKu2OmaVocbM+MPD7px92WoqY685aE2JdjM=; b=YslyDfD6zw+q7thrxfyouUBBzfUw75e+xz8EfKjn5Ab7Aazdx1SlpHnahLaj8Pzf3/ 7VyO29MShDho3de9bqGHfYcfiZgK7vJ6rNYEqfqCmuyTos1+1nE4RXtBdJ7FuSIGduB2 g627SS/0WB8YQ4cPI/ak6aqjoH3BWgKRjp94N/CehYcyvcYkkhvBWB4U4HUsAUwCnZpT lBJQZwud1+dhGH0iWR5jy0wBku3ZsNVqBcevSCSwd00HVTOOvK2vaNjd4h+VtABRj8U1 xzU1yiNfn8yMyb4IOvFkEsIM7/6vTwMqDLa2QXbYdcP/zwtMFgar7m66xyNd8PC+fgQP gKgQ== X-Gm-Message-State: ALoCoQky3/WSyUBrDkvnpTMROKywjAQlaiTmXdXnQQu0c2qUd6RrQ9SZ2pp7FoZrUJEVIq5fqQTi X-Received: by 10.70.118.197 with SMTP id ko5mr6875349pdb.137.1426155503134; Thu, 12 Mar 2015 03:18:23 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id z4sm10080331pdi.90.2015.03.12.03.18.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Mar 2015 03:18:22 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 12 Mar 2015 19:17:42 +0900 Message-Id: <1426155474-1596-4-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426155474-1596-1-git-send-email-mukawa@igel.co.jp> References: <1425438703-18895-1-git-send-email-mukawa@igel.co.jp> <1426155474-1596-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Mar 2015 10:18:24 -0000 When pci_map_resource() is failed but path is allocated correctly, path won't be freed. Also, when open() is failed, uio_res won't be freed. This patch fixes these. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c index 77bb5ed..901f277 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c @@ -350,6 +350,11 @@ pci_uio_map_resource(struct rte_pci_device *dev) loc->domain, loc->bus, loc->devid, loc->function, i); + /* allocate memory to keep path */ + maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); + if (maps[map_idx].path == NULL) + goto fail0; + /* * open resource file, to mmap it */ @@ -357,7 +362,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", devname, strerror(errno)); - return -1; + goto fail0; } /* try mapping somewhere close to the end of hugepages */ @@ -372,14 +377,9 @@ pci_uio_map_resource(struct rte_pci_device *dev) pci_map_addr = RTE_PTR_ADD(mapaddr, (size_t)dev->mem_resource[i].len); - maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); - if (maps[map_idx].path == NULL) - fail = 1; - if (fail) { - rte_free(uio_res); close(fd); - return -1; + goto fail1; } close(fd); @@ -397,6 +397,12 @@ pci_uio_map_resource(struct rte_pci_device *dev) TAILQ_INSERT_TAIL(uio_res_list, uio_res, next); return 0; + +fail1: + rte_free(maps[map_idx].path); +fail0: + rte_free(uio_res); + return -1; } #ifdef RTE_LIBRTE_EAL_HOTPLUG -- 1.9.1