get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/5764/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 5764,
    "url": "https://patches.dpdk.org/api/patches/5764/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1435202367-8887-4-git-send-email-mukawa@igel.co.jp/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1435202367-8887-4-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1435202367-8887-4-git-send-email-mukawa@igel.co.jp",
    "date": "2015-06-25T03:19:25",
    "name": "[dpdk-dev,v5,3/5] eal: Fix memory leaks and needless increment of pci_map_addr",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "705079e4dbfb4eb6c47c6de316adf98fb75b771a",
    "submitter": {
        "id": 64,
        "url": "https://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1435202367-8887-4-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/5764/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/5764/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 60187C530;\n\tThu, 25 Jun 2015 05:20:35 +0200 (CEST)",
            "from mail-pa0-f41.google.com (mail-pa0-f41.google.com\n\t[209.85.220.41]) by dpdk.org (Postfix) with ESMTP id EC6EBC52A\n\tfor <dev@dpdk.org>; Thu, 25 Jun 2015 05:20:33 +0200 (CEST)",
            "by pactm7 with SMTP id tm7so40925600pac.2\n\tfor <dev@dpdk.org>; Wed, 24 Jun 2015 20:20:33 -0700 (PDT)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby mx.google.com with ESMTPSA id\n\ttm3sm28482188pac.44.2015.06.24.20.20.31\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 24 Jun 2015 20:20:32 -0700 (PDT)"
        ],
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=bMVD7WYLBvkimgJJzAcsuGgPiWhW2rXBXbnZLQm+JVE=;\n\tb=ZSZ9P7M4YImoP+SxrqSfoW52jGlsw5YeC09z7SrZAipJ4WrYLoyvlE2zXTzC2OPGex\n\tYpm/Y5rm+bOg/G9Fjo0KH0tcXbQXHoNXwWoGGZ11+l0gIP73OhjD85OZg+oxcz1JRLB3\n\tYXOPLF2r0D14nG8+bf8Wtl5aU30Pu5Ka2BDXAxl0Qg3v+jtyJIlWWiX1s54Whtxok7kZ\n\tn0gm5azDG2sHbultYtPjQwHEE9Tcc+55cbTH6Jtn0TDLmd+PGYJBQepW7Nu4CB6BMnaj\n\tWzljsMbdBmagzcistJCjjSbOIYcCzPff2UBzdEGc3qtDJVLZmLb0aFTu9PoisUN0XhpZ\n\tZAJw==",
        "X-Gm-Message-State": "ALoCoQkDAGBbN73JIrasA+O4hQCfZOcveldbL/rHGPW4yXlZwM5keV6oX74oe+yJ9tATUMAgF4Yb",
        "X-Received": "by 10.66.234.134 with SMTP id ue6mr85727875pac.146.1435202433295;\n\tWed, 24 Jun 2015 20:20:33 -0700 (PDT)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org",
        "Date": "Thu, 25 Jun 2015 12:19:25 +0900",
        "Message-Id": "<1435202367-8887-4-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 2.1.4",
        "In-Reply-To": "<1435202367-8887-1-git-send-email-mukawa@igel.co.jp>",
        "References": "<1432014898-3543-2-git-send-email-mukawa@igel.co.jp>\n\t<1435202367-8887-1-git-send-email-mukawa@igel.co.jp>",
        "Subject": "[dpdk-dev] [PATCH v5 3/5] eal: Fix memory leaks and needless\n\tincrement of pci_map_addr",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: \"Tetsuya.Mukawa\" <mukawa@igel.co.jp>\n\nThis patch fixes following memory leaks.\n- When open() is failed, uio_res and fds won't be freed in\n  pci_uio_map_resource().\n- When pci_map_resource() is failed but path is allocated correctly,\n  path and fds won't be freed in pci_uio_map_recource().\n- When pci_uio_unmap() is called, path should be freed.\n\nAlso, fixes below.\n- When pci_map_resource() is failed, mapaddr will be MAP_FAILED.\n  In this case, pci_map_addr should not be incremented in\n  pci_uio_map_resource().\n- To shrink code, move close().\n- Remove fail variable.\n\nSigned-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>\n---\n lib/librte_eal/bsdapp/eal/eal_pci.c       | 14 +++++++--\n lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 51 ++++++++++++++++++++-----------\n 2 files changed, 44 insertions(+), 21 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c\nindex 8e24fd1..b071f07 100644\n--- a/lib/librte_eal/bsdapp/eal/eal_pci.c\n+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c\n@@ -235,7 +235,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif ((uio_res = rte_zmalloc(\"UIO_RES\", sizeof (*uio_res), 0)) == NULL) {\n \t\tRTE_LOG(ERR, EAL,\n \t\t\t\"%s(): cannot store uio mmap details\\n\", __func__);\n-\t\treturn -1;\n+\t\tgoto close_fd;\n \t}\n \n \tsnprintf(uio_res->path, sizeof(uio_res->path), \"%s\", devname);\n@@ -262,8 +262,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\t    (mapaddr = pci_map_resource(NULL, devname, (off_t)offset,\n \t\t\t\t\t\t(size_t)maps[j].size)\n \t\t    ) == NULL) {\n-\t\t\trte_free(uio_res);\n-\t\t\treturn -1;\n+\t\t\tgoto free_uio_res;\n \t\t}\n \n \t\tmaps[j].addr = mapaddr;\n@@ -274,6 +273,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tTAILQ_INSERT_TAIL(uio_res_list, uio_res, next);\n \n \treturn 0;\n+\n+free_uio_res:\n+\trte_free(uio_res);\n+close_fd:\n+\tclose(dev->intr_handle.fd);\n+\tdev->intr_handle.fd = -1;\n+\tdev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;\n+\n+\treturn -1;\n }\n \n /* Scan one pci sysfs entry, and fill the devices list from it. */\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\nindex 34316b6..2dd83d3 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c\n@@ -308,7 +308,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (dev->intr_handle.uio_cfg_fd < 0) {\n \t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\tcfgname, strerror(errno));\n-\t\treturn -1;\n+\t\tgoto close_fd;\n \t}\n \n \tif (dev->kdrv == RTE_KDRV_IGB_UIO)\n@@ -328,7 +328,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tif (uio_res == NULL) {\n \t\tRTE_LOG(ERR, EAL,\n \t\t\t\"%s(): cannot store uio mmap details\\n\", __func__);\n-\t\treturn -1;\n+\t\tgoto close_fd;\n \t}\n \n \tsnprintf(uio_res->path, sizeof(uio_res->path), \"%s\", devname);\n@@ -338,7 +338,6 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tmaps = uio_res->maps;\n \tfor (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {\n \t\tint fd;\n-\t\tint fail = 0;\n \n \t\t/* skip empty BAR */\n \t\tphaddr = dev->mem_resource[i].phys_addr;\n@@ -352,6 +351,11 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\t\t\tloc->domain, loc->bus, loc->devid, loc->function,\n \t\t\t\ti);\n \n+\t\t/* allocate memory to keep path */\n+\t\tmaps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);\n+\t\tif (maps[map_idx].path == NULL)\n+\t\t\tgoto free_uio_res;\n+\n \t\t/*\n \t\t * open resource file, to mmap it\n \t\t */\n@@ -359,7 +363,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \t\tif (fd < 0) {\n \t\t\tRTE_LOG(ERR, EAL, \"Cannot open %s: %s\\n\",\n \t\t\t\t\tdevname, strerror(errno));\n-\t\t\treturn -1;\n+\t\t\trte_free(maps[map_idx].path);\n+\t\t\tgoto free_uio_res;\n \t\t}\n \n \t\t/* try mapping somewhere close to the end of hugepages */\n@@ -368,23 +373,15 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \n \t\tmapaddr = pci_map_resource(pci_map_addr, fd, 0,\n \t\t\t\t(size_t)dev->mem_resource[i].len, 0);\n-\t\tif (mapaddr == MAP_FAILED)\n-\t\t\tfail = 1;\n+\t\tclose(fd);\n+\t\tif (mapaddr == MAP_FAILED) {\n+\t\t\trte_free(maps[map_idx].path);\n+\t\t\tgoto free_uio_res;\n+\t\t}\n \n \t\tpci_map_addr = RTE_PTR_ADD(mapaddr,\n \t\t\t\t(size_t)dev->mem_resource[i].len);\n \n-\t\tmaps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);\n-\t\tif (maps[map_idx].path == NULL)\n-\t\t\tfail = 1;\n-\n-\t\tif (fail) {\n-\t\t\trte_free(uio_res);\n-\t\t\tclose(fd);\n-\t\t\treturn -1;\n-\t\t}\n-\t\tclose(fd);\n-\n \t\tmaps[map_idx].phaddr = dev->mem_resource[i].phys_addr;\n \t\tmaps[map_idx].size = dev->mem_resource[i].len;\n \t\tmaps[map_idx].addr = mapaddr;\n@@ -399,6 +396,22 @@ pci_uio_map_resource(struct rte_pci_device *dev)\n \tTAILQ_INSERT_TAIL(uio_res_list, uio_res, next);\n \n \treturn 0;\n+\n+free_uio_res:\n+\tfor (i = 0; i < map_idx; i++)\n+\t\trte_free(maps[i].path);\n+\trte_free(uio_res);\n+close_fd:\n+\tif (dev->intr_handle.uio_cfg_fd >= 0) {\n+\t\tclose(dev->intr_handle.uio_cfg_fd);\n+\t\tdev->intr_handle.uio_cfg_fd = -1;\n+\t}\n+\n+\tclose(dev->intr_handle.fd);\n+\tdev->intr_handle.fd = -1;\n+\tdev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;\n+\n+\treturn -1;\n }\n \n #ifdef RTE_LIBRTE_EAL_HOTPLUG\n@@ -410,9 +423,11 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)\n \tif (uio_res == NULL)\n \t\treturn;\n \n-\tfor (i = 0; i != uio_res->nb_maps; i++)\n+\tfor (i = 0; i != uio_res->nb_maps; i++) {\n \t\tpci_unmap_resource(uio_res->maps[i].addr,\n \t\t\t\t(size_t)uio_res->maps[i].size);\n+\t\trte_free(uio_res->maps[i].path);\n+\t}\n }\n \n static struct mapped_pci_resource *\n",
    "prefixes": [
        "dpdk-dev",
        "v5",
        "3/5"
    ]
}