* [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request
@ 2018-11-23 14:11 Darek Stojaczyk
2018-11-23 19:17 ` Zhang, Qi Z
0 siblings, 1 reply; 3+ messages in thread
From: Darek Stojaczyk @ 2018-11-23 14:11 UTC (permalink / raw)
To: dev; +Cc: thomas, Darek Stojaczyk, qi.z.zhang
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 <dariusz.stojaczyk@intel.com>
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request
2018-11-23 14:11 [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request Darek Stojaczyk
@ 2018-11-23 19:17 ` Zhang, Qi Z
2018-11-25 12:33 ` Thomas Monjalon
0 siblings, 1 reply; 3+ messages in thread
From: Zhang, Qi Z @ 2018-11-23 19:17 UTC (permalink / raw)
To: Stojaczyk, Dariusz, dev; +Cc: thomas
> -----Original Message-----
> From: Stojaczyk, Dariusz
> Sent: Friday, November 23, 2018 6:11 AM
> To: dev@dpdk.org
> Cc: thomas@monjalon.net; Stojaczyk, Dariusz <dariusz.stojaczyk@intel.com>;
> Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: [PATCH] dev: fix devargs memleak on IPC 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")
> Cc: qi.z.zhang@intel.com
>
> Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Acked-by: Qi Zhang <qi.z.zhang@intel.com>
Thanks
Qi
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request
2018-11-23 19:17 ` Zhang, Qi Z
@ 2018-11-25 12:33 ` Thomas Monjalon
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2018-11-25 12:33 UTC (permalink / raw)
To: Stojaczyk, Dariusz; +Cc: dev, Zhang, Qi Z
23/11/2018 20:17, Zhang, Qi Z:
> From: Stojaczyk, Dariusz
> > 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 <dariusz.stojaczyk@intel.com>
>
> Acked-by: Qi Zhang <qi.z.zhang@intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-25 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-23 14:11 [dpdk-dev] [PATCH] dev: fix devargs memleak on IPC detach request Darek Stojaczyk
2018-11-23 19:17 ` Zhang, Qi Z
2018-11-25 12:33 ` Thomas Monjalon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).