From 04e0cf6aee78317cb226ad910fe2c53b501dfec5 Mon Sep 17 00:00:00 2001 From: Ric Date: Thu, 26 Jan 2023 20:41:05 -0500 Subject: [PATCH] fix leaks in tests --- sketcherMinimizerMolecule.cpp | 3 ++- test/test_coordgen.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/sketcherMinimizerMolecule.cpp b/sketcherMinimizerMolecule.cpp index 49094f1..ff9c922 100644 --- a/sketcherMinimizerMolecule.cpp +++ b/sketcherMinimizerMolecule.cpp @@ -24,8 +24,9 @@ sketcherMinimizerMolecule::sketcherMinimizerMolecule() sketcherMinimizerMolecule::~sketcherMinimizerMolecule() { - for (auto ring : _rings) { + for (auto& ring : _rings) { delete ring; + ring = nullptr; } } diff --git a/test/test_coordgen.cpp b/test/test_coordgen.cpp index a4cf045..aec0738 100644 --- a/test/test_coordgen.cpp +++ b/test/test_coordgen.cpp @@ -15,6 +15,9 @@ #include "maeparser/MaeConstants.hpp" #include "maeparser/Reader.hpp" +// The sketcherMinimizerFragment class is not exposed in the library +#include "../sketcherMinimizerFragment.cpp" + using std::unordered_set; using namespace schrodinger; @@ -498,6 +501,15 @@ BOOST_AUTO_TEST_CASE(testClockwiseOrderedNaN) sketcherMinimizerAtom* neigh1 = atoms.at(1); neigh1->coordinates = sketcherMinimizerPointF(std::nanf("name"), std::nanf("name")); const auto orderedNeighbors = center->clockwiseOrderedNeighbors(); + + // We usually allow the sketcher minimizer to clean up bonds & atoms, + // but we don't have a minimizer here + for (auto& bond : mol->getBonds()) { + delete bond; + } + for (auto& atom : atoms) { + delete atom; + } } @@ -639,4 +651,8 @@ BOOST_AUTO_TEST_CASE(testCoordgenFragmenter) // Fragment containing atoms (9, 10) BOOST_TEST(atoms[8]->fragment->constrained == false); BOOST_TEST(atoms[8]->fragment->constrainedFlip == false); + + for (auto& fragment : mol->_fragments) { + delete fragment; + } }