From 60e97921f1e7e129b6e1a800aa2ea6d8a3eb8678 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Wed, 6 Jan 2021 20:35:57 -0700 Subject: [PATCH] Fix memory leaks in Multilevel_(MQ|Modularity)_Clustering_establish --- lib/sparse/clustering.c | 10 ++++++++-- lib/sparse/mq.c | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/sparse/clustering.c b/lib/sparse/clustering.c index 86fe04e29..ae4eeb33a 100644 --- a/lib/sparse/clustering.c +++ b/lib/sparse/clustering.c @@ -223,9 +223,15 @@ static Multilevel_Modularity_Clustering Multilevel_Modularity_Clustering_establi SparseMatrix_delete(R0); P = SparseMatrix_transpose(R); B = SparseMatrix_multiply(R, A); - if (!B) goto RETURN; + if (!B) { + FREE(deg_new); + goto RETURN; + } cA = SparseMatrix_multiply(B, P); - if (!cA) goto RETURN; + if (!cA) { + FREE(deg_new); + goto RETURN; + } SparseMatrix_delete(B); grid->P = P; grid->R = R; diff --git a/lib/sparse/mq.c b/lib/sparse/mq.c index 5fb0658d8..bdf40575f 100644 --- a/lib/sparse/mq.c +++ b/lib/sparse/mq.c @@ -471,9 +471,19 @@ static Multilevel_MQ_Clustering Multilevel_MQ_Clustering_establish(Multilevel_MQ SparseMatrix_delete(R0); P = SparseMatrix_transpose(R); B = SparseMatrix_multiply(R, A); - if (!B) goto RETURN; + if (!B) { + FREE(deg_intra_new); + FREE(wgt_new); + FREE(dout_new); + goto RETURN; + } cA = SparseMatrix_multiply(B, P); - if (!cA) goto RETURN; + if (!cA) { + FREE(deg_intra_new); + FREE(wgt_new); + FREE(dout_new); + goto RETURN; + } SparseMatrix_delete(B); grid->P = P; grid->R = R; -- 2.40.0