summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarek Stojaczyk <dariusz.stojaczyk@intel.com>2018-11-23 15:11:07 +0100
committerThomas Monjalon <thomas@monjalon.net>2018-11-25 13:32:01 +0100
commit29bf7e93baa3d53e1773f2cfdade8706da2bde51 (patch)
treed1960c88163312bd491eca1b2bde52152557d916
parent494db286f37ddbb88cd5b9d84dd9b18d1a797e5c (diff)
downloaddpdk-29bf7e93baa3d53e1773f2cfdade8706da2bde51.zip
dpdk-29bf7e93baa3d53e1773f2cfdade8706da2bde51.tar.gz
dpdk-29bf7e93baa3d53e1773f2cfdade8706da2bde51.tar.xz
eal: fix devargs leak on multi-process detach request
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") Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Acked-by: Qi Zhang <qi.z.zhang@intel.com>
-rw-r--r--lib/librte_eal/common/hotplug_mp.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c
index ed0d7d3..070e2e0 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;
}