]> granicus.if.org Git - graphviz/commitdiff
dotgen cluster: fix memory leaks by freeing data from removed rank leaders
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 18 Jul 2022 07:47:15 +0000 (09:47 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 25 Jul 2022 18:24:49 +0000 (20:24 +0200)
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
lib/dotgen/cluster.c

index 7f07228e5e43aee4b640a3036d04e77e6f2c79c5..3bebe7200b8a15f7ceb91b37da9d91e822391bc1 100644 (file)
@@ -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
 
index 95c7544d45953b5647a5a44a2f05c4cde160d58c..1ce49887f06e6eb118b1e378d8f759a7eaaf2ced 100644 (file)
@@ -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;
     }
 }