DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] examples/bbdev: fix memory leak
@ 2018-01-31 14:30 Amr Mokhtar
  2018-01-31 17:29 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Amr Mokhtar @ 2018-01-31 14:30 UTC (permalink / raw)
  To: dev; +Cc: Amr Mokhtar

xstats and xstats_names buffers were allocated for
the purpose of printing eth_xstats, but were not
freed before exit.
A fix is added to free before exit points.

Coverity issue: 257013
Fixes: 1ffee690eaa1 ("examples/bbdev: add sample app")

Signed-off-by: Amr Mokhtar <amr.mokhtar@intel.com>
---
 examples/bbdev_app/main.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/examples/bbdev_app/main.c b/examples/bbdev_app/main.c
index 2e5bd8c..ef0ca25 100644
--- a/examples/bbdev_app/main.c
+++ b/examples/bbdev_app/main.c
@@ -585,21 +585,28 @@ print_stats(struct stats_lcore_params *stats_lcore)
 				"Failed to calloc memory for xstats");
 
 	ret = rte_eth_xstats_get(port_id, xstats, len);
-	if (ret < 0 || ret > len)
+	if (ret < 0 || ret > len) {
+		free(xstats);
 		rte_exit(EXIT_FAILURE,
 				"rte_eth_xstats_get(%u) len%i failed: %d",
 				port_id, len, ret);
+	}
 
 	xstats_names = calloc(len, sizeof(*xstats_names));
-	if (xstats_names == NULL)
+	if (xstats_names == NULL) {
+		free(xstats);
 		rte_exit(EXIT_FAILURE,
 				"Failed to calloc memory for xstats_names");
+	}
 
 	ret = rte_eth_xstats_get_names(port_id, xstats_names, len);
-	if (ret < 0 || ret > len)
+	if (ret < 0 || ret > len) {
+		free(xstats);
+		free(xstats_names);
 		rte_exit(EXIT_FAILURE,
 				"rte_eth_xstats_get_names(%u) len%i failed: %d",
 				port_id, len, ret);
+	}
 
 	for (i = 0; i < len; i++) {
 		if (xstats[i].value > 0)
@@ -630,6 +637,9 @@ print_stats(struct stats_lcore_params *stats_lcore)
 			continue;
 		print_lcore_stats(stats_lcore->lconf[l_id].lcore_stats, l_id);
 	}
+
+	free(xstats);
+	free(xstats_names);
 }
 
 static int
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] examples/bbdev: fix memory leak
  2018-01-31 14:30 [dpdk-dev] [PATCH] examples/bbdev: fix memory leak Amr Mokhtar
@ 2018-01-31 17:29 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2018-01-31 17:29 UTC (permalink / raw)
  To: Amr Mokhtar; +Cc: dev

31/01/2018 15:30, Amr Mokhtar:
> xstats and xstats_names buffers were allocated for
> the purpose of printing eth_xstats, but were not
> freed before exit.
> A fix is added to free before exit points.
> 
> Coverity issue: 257013
> Fixes: 1ffee690eaa1 ("examples/bbdev: add sample app")
> 
> Signed-off-by: Amr Mokhtar <amr.mokhtar@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-31 17:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31 14:30 [dpdk-dev] [PATCH] examples/bbdev: fix memory leak Amr Mokhtar
2018-01-31 17:29 ` 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).