get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 4792,
    "url": "http://patches.dpdk.org/api/patches/4792/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1432014898-3543-4-git-send-email-mukawa@igel.co.jp/",
    "project": {
        "id": 1,
        "url": "http://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": "<1432014898-3543-4-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1432014898-3543-4-git-send-email-mukawa@igel.co.jp",
    "date": "2015-05-19T05:54:56",
    "name": "[dpdk-dev,v4,3/5] eal: Fix memory leaks and needless increment of pci_map_addr",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "705079e4dbfb4eb6c47c6de316adf98fb75b771a",
    "submitter": {
        "id": 64,
        "url": "http://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1432014898-3543-4-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/4792/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/4792/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 F2717C344;\n\tTue, 19 May 2015 07:55:31 +0200 (CEST)",
            "from mail-pd0-f172.google.com (mail-pd0-f172.google.com\n\t[209.85.192.172]) by dpdk.org (Postfix) with ESMTP id F203AC354\n\tfor <dev@dpdk.org>; Tue, 19 May 2015 07:55:28 +0200 (CEST)",
            "by pdbqa5 with SMTP id qa5so9299241pdb.0\n\tfor <dev@dpdk.org>; Mon, 18 May 2015 22:55:28 -0700 (PDT)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby mx.google.com with ESMTPSA id\n\tqz7sm11796528pbc.11.2015.05.18.22.55.26\n\t(version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tMon, 18 May 2015 22:55:27 -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=n+2bbCjEqPvS9K8NJIpHg8wwrIR9aA1OzYCkNQbLLkc=;\n\tb=LDLcsqhopoJ5YWsgMIb8WfuYcHojmG8C3D5/SGVGWcPb99s+siDmd+845InrUOeyZ1\n\tLjTQ9kwLr3FCsn6LBM17mxRz6wLpYWA/DT8Vuq/7YCDf6ruIpvIw1i79TcibKzCVX2Xt\n\txheEqeORmq9XaOv+pTRwn8dncQQXZtqky9o0zExqQsl8A+FWfHmuKdyiTK9VSve7YovV\n\txi6O95UZvONHUpuIkoYj4Of05FFgRGSFsCR7gUpCJB20HSBwWUUm8JltAjfA28caEGy3\n\t7gx795+pS2ag91AvOKt5mso00JMe7JoWBzD+/o+u/6SRN1TauX4Zh2+DfVuboncVdR4I\n\tEe4A==",
        "X-Gm-Message-State": "ALoCoQkJhJ5VC1vSxt/Wr6K8pRW0B6Xl0M1pHS2eOS5pr2cF1MHbvRPDKHApECs/NpuKrWSG+UkZ",
        "X-Received": "by 10.68.242.41 with SMTP id wn9mr49993808pbc.117.1432014928241; \n\tMon, 18 May 2015 22:55:28 -0700 (PDT)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org",
        "Date": "Tue, 19 May 2015 14:54:56 +0900",
        "Message-Id": "<1432014898-3543-4-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 2.1.4",
        "In-Reply-To": "<1432014898-3543-1-git-send-email-mukawa@igel.co.jp>",
        "References": "<1432014898-3543-1-git-send-email-mukawa@igel.co.jp>",
        "Subject": "[dpdk-dev] [PATCH v4 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": "This 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",
        "v4",
        "3/5"
    ]
}