[dpdk-dev] eal: fix leak in hotplug add on parse error

Message ID 90dae107bf7e55ec42ae8223d5666a77bd9ddfe7.1501763614.git.gaetan.rivet@6wind.com (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gaëtan Rivet Aug. 3, 2017, 12:34 p.m. UTC
  If rte_eal_devargs_parse fails, the rte_devargs has not yet been inserted
in the global list. When jumping to err_devarg, the removal fails and it
is not properly freed.

Free the allocated rte_devargs if its removal failed.

Coverity issue: 158658
Fixes: 7e8b26650146 ("eal: fix hotplug add / remove")

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_dev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Aug. 3, 2017, 8:06 p.m. UTC | #1
03/08/2017 14:34, Gaetan Rivet:
> If rte_eal_devargs_parse fails, the rte_devargs has not yet been inserted
> in the global list. When jumping to err_devarg, the removal fails and it
> is not properly freed.
> 
> Free the allocated rte_devargs if its removal failed.
> 
> Coverity issue: 158658
> Fixes: 7e8b26650146 ("eal: fix hotplug add / remove")
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index d19232d..fc8a4d2 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -204,7 +204,10 @@  int rte_eal_hotplug_add(const char *busname, const char *devname,
 	return 0;
 
 err_devarg:
-	rte_eal_devargs_remove(busname, devname);
+	if (rte_eal_devargs_remove(busname, devname)) {
+		free(da->args);
+		free(da);
+	}
 err_name:
 	free(name);
 	return ret;