From 961575c6a5e7952273cf42a35b25159f775b958b Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Mon, 18 Jul 2022 09:47:15 +0200 Subject: [PATCH] dotgen cluster: fix memory leaks by freeing data from removed rank leaders The `build_skeleton` function inserts virtual nodes and edges into the graph to be used by the clustering algorithms. The `expand_cluster` function later installs real nodes or sub-clusters and deletes the virtual nodes and edges by calling the `remove_rank_leaders` function which removes these from the graph. However, it didn't free the data allocated for them which caused several memory leaks. --- CHANGELOG.md | 1 + lib/dotgen/cluster.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f07228e5..3bebe7200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Dot] Record shape+UTF+" | "=Eats spaces. #925 - Memory leak in osage - Segmentation fault when running test example neatopack.c #1800 +- Memory leak in dot when using clusters ## [5.0.0] – 2022-07-07 diff --git a/lib/dotgen/cluster.c b/lib/dotgen/cluster.c index 95c7544d4..1ce49887f 100644 --- a/lib/dotgen/cluster.c +++ b/lib/dotgen/cluster.c @@ -267,11 +267,20 @@ remove_rankleaders(graph_t * g) v = GD_rankleader(g)[r]; /* remove the entire chain */ - while ((e = ND_out(v).list[0])) + while ((e = ND_out(v).list[0])) { delete_fast_edge(e); - while ((e = ND_in(v).list[0])) + free(e->base.data); + free(e); + } + while ((e = ND_in(v).list[0])) { delete_fast_edge(e); + free(e); + } delete_fast_node(dot_root(g), v); + free(ND_in(v).list); + free(ND_out(v).list); + free(v->base.data); + free(v); GD_rankleader(g)[r] = NULL; } } -- 2.40.0