]> granicus.if.org Git - graphviz/commitdiff
sfdpgen spring_electrical_embedding_slow: fix memory leak
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 27 Nov 2022 19:24:35 +0000 (11:24 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 30 Nov 2022 01:04:39 +0000 (17:04 -0800)
`qtree_level_optimizer` would be optionally allocated based on
`n >= ctrl->quadtree_size` but then would only be freed if `USE_QT` was set.
`USE_QT` is always false (it will be removed in an upcoming commit), so this
clean up never runs. This seems latent; I suspect the branch that allocates
`qtree_level_optimizer` is unreachable because this function appears to have
been copy-pasted from one of the other variants in this file with little regard
to how much of it is dead code. But it still seems wise to fix this issue.

lib/sfdpgen/spring_electrical.c

index 6f7aee651df0c055add0c588546366c82cda1cae..6d7642003f7e89194df4ed74a05abd73e3378c1c 100644 (file)
@@ -869,9 +869,9 @@ static void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_el
 
  RETURN:
   if (USE_QT) {
-    oned_optimizer_delete(qtree_level_optimizer);
     ctrl->max_qtree_level = max_qtree_level;
   }
+  oned_optimizer_delete(qtree_level_optimizer);
   free(xold);
   if (A != A0) SparseMatrix_delete(A);
   free(f);