From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 3FAFF1B572 for ; Fri, 23 Nov 2018 15:24:46 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Nov 2018 06:24:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,270,1539673200"; d="scan'208";a="110579641" Received: from violet.igk.intel.com ([10.102.54.137]) by fmsmga001.fm.intel.com with ESMTP; 23 Nov 2018 06:24:44 -0800 From: Darek Stojaczyk To: dev@dpdk.org Cc: thomas@monjalon.net, Darek Stojaczyk , qi.z.zhang@intel.com Date: Fri, 23 Nov 2018 15:11:07 +0100 Message-Id: <20181123141107.86553-1-dariusz.stojaczyk@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Nov 2018 14:24:47 -0000 Device detach triggered through IPC leaked some memory. It allocated a devargs objects just to use it for parsing the devargs string in order to retrieve the device name. Those devargs weren't passed anywhere and were never freed. First of all, let's put those devargs on the stack, so they doesn't need to be freed. Then free the additional arguments string as soon as it's allocated, because we won't need it. Fixes: ac9e4a17370f ("eal: support attach/detach shared device from secondary") Cc: qi.z.zhang@intel.com Signed-off-by: Darek Stojaczyk --- lib/librte_eal/common/hotplug_mp.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c index 7c9fcc46c..0a822e4c7 100644 --- a/lib/librte_eal/common/hotplug_mp.c +++ b/lib/librte_eal/common/hotplug_mp.c @@ -87,7 +87,7 @@ __handle_secondary_request(void *param) const struct eal_dev_mp_req *req = (const struct eal_dev_mp_req *)msg->param; struct eal_dev_mp_req tmp_req; - struct rte_devargs *da; + struct rte_devargs da; struct rte_device *dev; struct rte_bus *bus; int ret = 0; @@ -114,15 +114,11 @@ __handle_secondary_request(void *param) goto rollback; } } else if (req->t == EAL_DEV_REQ_TYPE_DETACH) { - da = calloc(1, sizeof(*da)); - if (da == NULL) { - ret = -ENOMEM; - goto finish; - } - - ret = rte_devargs_parse(da, req->devargs); + ret = rte_devargs_parse(&da, req->devargs); if (ret != 0) goto finish; + free(da.args); /* we don't need those */ + da.args = NULL; ret = eal_dev_hotplug_request_to_secondary(&tmp_req); if (ret != 0) { @@ -131,16 +127,16 @@ __handle_secondary_request(void *param) goto rollback; } - bus = rte_bus_find_by_name(da->bus->name); + bus = rte_bus_find_by_name(da.bus->name); if (bus == NULL) { - RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", da->bus->name); + RTE_LOG(ERR, EAL, "Cannot find bus (%s)\n", da.bus->name); ret = -ENOENT; goto finish; } - dev = bus->find_device(NULL, cmp_dev_name, da->name); + dev = bus->find_device(NULL, cmp_dev_name, da.name); if (dev == NULL) { - RTE_LOG(ERR, EAL, "Cannot find plugged device (%s)\n", da->name); + RTE_LOG(ERR, EAL, "Cannot find plugged device (%s)\n", da.name); ret = -ENOENT; goto finish; } -- 2.17.1