From eebad845f551b6b15f0655589a5ab67e52f8f53f Mon Sep 17 00:00:00 2001 From: Greg Landrum Date: Thu, 21 Mar 2024 12:56:41 +0100 Subject: [PATCH] fix a leak in the new DCLV code (#7279) --- Code/GraphMol/Descriptors/DCLV.cpp | 16 ++++++++++++++++ Code/GraphMol/Descriptors/DCLV.h | 3 ++- .../Descriptors/Wrap/rdMolDescriptors.cpp | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Code/GraphMol/Descriptors/DCLV.cpp b/Code/GraphMol/Descriptors/DCLV.cpp index d6894291a60..8572f8e45ca 100644 --- a/Code/GraphMol/Descriptors/DCLV.cpp +++ b/Code/GraphMol/Descriptors/DCLV.cpp @@ -352,12 +352,27 @@ struct State { void freeAtomList(AtomList* ptr) { while (ptr) { AtomList* next = ptr->next; +#if 0 ptr->next = freeList; freeList = ptr; +#else + free(ptr); +#endif ptr = next; } } + void freeGrid() { + for (unsigned int x = 0; x < VOXORDER; x++) { + for (unsigned int y = 0; y < VOXORDER; y++) { + for (unsigned int z = 0; z < VOXORDER; z++) { + freeAtomList(grid[x][y][z]); + grid[x][y][z] = nullptr; + } + } + } + } + ElemStruct* getAtomElem(std::string atmName, bool typeFlag) { const char* name = atmName.c_str(); @@ -856,6 +871,7 @@ DoubleCubicLatticeVolume::DoubleCubicLatticeVolume(const ROMol& mol, vdwVolume = s.calculateVolume(0.0, memberAtoms); compactness = calculateCompactness(surfaceArea, totalVolume); packingDensity = (vdwVolume / totalVolume); + s.freeGrid(); } } // namespace Descriptors diff --git a/Code/GraphMol/Descriptors/DCLV.h b/Code/GraphMol/Descriptors/DCLV.h index f4138f2701a..9b45f00c866 100644 --- a/Code/GraphMol/Descriptors/DCLV.h +++ b/Code/GraphMol/Descriptors/DCLV.h @@ -32,7 +32,8 @@ class RDKIT_DESCRIPTORS_EXPORT DoubleCubicLatticeVolume { \param mol: input molecule or protein \param isProtein: flag to identify input as protein vs unbound ligand - (default=true, Protein as input) + (default=true, Protein as input) NOTE that the results for isProtein=false + are currently not correct \param includeLigand: flag to trigger inclusion of bound ligand in surface area and volume calculations where molecule is a protein [default false] diff --git a/Code/GraphMol/Descriptors/Wrap/rdMolDescriptors.cpp b/Code/GraphMol/Descriptors/Wrap/rdMolDescriptors.cpp index b635f8ca2a0..edaf86a175f 100644 --- a/Code/GraphMol/Descriptors/Wrap/rdMolDescriptors.cpp +++ b/Code/GraphMol/Descriptors/Wrap/rdMolDescriptors.cpp @@ -1657,6 +1657,7 @@ BOOST_PYTHON_MODULE(rdMolDescriptors) { docString = R"DOC(ARGUMENTS: " - mol: molecule or protein under consideration + " - isProtein: flag to indicate if the input is a protein (default=True). NOTE that results with isProtein=False are currently not correct. " - includeLigand: flag to include or exclude a bound ligand when input is a protein (default=False) " - probeRadius: radius of the solvent probe (default=1.4) " - depth: control of number of dots per atom (default=2)