diff mbox series

[v2,1/2] graph: fix memory leak

Message ID 1620285387-42792-2-git-send-email-humin29@huawei.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers show
Series bugfix for graph | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) May 6, 2021, 7:16 a.m. UTC
From: HongBo Zheng <zhenghongbo3@huawei.com>

Fix function 'stats_mem_populate' return without
free dynamic memory referenced by 'stats'.

Fixes: af1ae8b6a32c ("graph: implement stats")
Cc: stable@dpdk.org

Signed-off-by: HongBo Zheng <zhenghongbo3@huawei.com>
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 lib/graph/graph_stats.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

David Marchand May 10, 2021, 1:26 p.m. UTC | #1
On Thu, May 6, 2021 at 9:16 AM Min Hu (Connor) <humin29@huawei.com> wrote:
>
> From: HongBo Zheng <zhenghongbo3@huawei.com>
>
> Fix function 'stats_mem_populate' return without
> free dynamic memory referenced by 'stats'.
>
> Fixes: af1ae8b6a32c ("graph: implement stats")
> Cc: stable@dpdk.org
>
> Signed-off-by: HongBo Zheng <zhenghongbo3@huawei.com>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>

Reviewed-by: David Marchand <david.marchand@redhat.com>
diff mbox series

Patch

diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c
index 125e08d..30e295d 100644
--- a/lib/graph/graph_stats.c
+++ b/lib/graph/graph_stats.c
@@ -165,6 +165,7 @@  stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	stats = realloc(stats, stats->sz + stats->cluster_node_size);
 	if (stats == NULL)
 		SET_ERR_JMP(ENOMEM, err, "Realloc failed");
+	*stats_in = NULL;
 
 	/* Clear the new struct cluster_node area */
 	cluster = RTE_PTR_ADD(stats, stats->sz),
@@ -174,7 +175,7 @@  stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	cluster->stat.hz = rte_get_timer_hz();
 	node = graph_node_id_to_ptr(graph, id);
 	if (node == NULL)
-		SET_ERR_JMP(ENOENT, err, "Failed to find node %s in graph %s",
+		SET_ERR_JMP(ENOENT, free, "Failed to find node %s in graph %s",
 			    graph_node->node->name, graph->name);
 	cluster->nodes[cluster->nb_nodes++] = node;
 
@@ -183,6 +184,8 @@  stats_mem_populate(struct rte_graph_cluster_stats **stats_in,
 	*stats_in = stats;
 
 	return 0;
+free:
+	free(stats);
 err:
 	return -rte_errno;
 }