From 3b47572fbe783ced8264bc7de459121e201c5bef Mon Sep 17 00:00:00 2001 From: Hongbo Zheng Date: Thu, 6 May 2021 15:16:26 +0800 Subject: [PATCH] graph: fix memory leak in stats 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 Signed-off-by: Min Hu (Connor) Reviewed-by: David Marchand --- lib/graph/graph_stats.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/graph/graph_stats.c b/lib/graph/graph_stats.c index 125e08d732..30e295d8b1 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; } -- 2.20.1