Skip to content

Commit

Permalink
graph: fix memory leak in stats
Browse files Browse the repository at this point in the history
[ upstream commit 3b47572 ]

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

Fixes: af1ae8b ("graph: implement stats")

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>
  • Loading branch information
Hongbo Zheng authored and bluca committed Jul 12, 2021
1 parent a860247 commit 3d328cf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/librte_graph/graph_stats.c
Expand Up @@ -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),
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down

0 comments on commit 3d328cf

Please sign in to comment.