Hi all, I am tracking down a memory issue triggered by OpFillUC::Do, but which happens deep down in the bowels of openbabel. Since I'm new to this project, I don't have a good view of its overall architecture and I'm having a hard time finding what happens and how to correct it, so I'm asking here for help!
Now, let's get to it. I am chasing down a memory issue that sometimes shows up when using "babel --fillUC" as an OS warning ("incorrect checksum for freed object - object was probably modified after being freed"). As such, I ran openbabel under valgrind, which shows a series of invalid reads when using "babel --fillUC" which aren't encountered when doing the same conversion without --fillUC. The first of these messages is: > Invalid read of size 8 > at 0xD759A: OpenBabel::OBSmartsPattern::GetCharge(int) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0xE1C20: OpenBabel::OBChemTsfm::Init(std::string&, std::string&) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0xE0D1C: OpenBabel::OBPhModel::ParseLine(char const*) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x4A79E: OpenBabel::OBGlobalDataBase::Init() (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0xE1EBC: > OpenBabel::OBPhModel::AssignSeedPartialCharge(OpenBabel::OBMol&) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x1E767: OpenBabel::OBAtom::GetPartialCharge() (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x21AB3: OpenBabel::OBAtom::Duplicate(OpenBabel::OBAtom*) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x1190CE6: OpenBabel::OpFillUC::Do(OpenBabel::OBBase*, char const*, > std::map<std::string, std::string, std::less<std::string>, > std::allocator<std::pair<std::string const, std::string> > > const*, > OpenBabel::OBConversion*) (in > /opt/openbabel-2.3.1/lib/openbabel/2.3.1/plugin_ops.so) > by 0x10139D: OpenBabel::OBOp::DoOps(OpenBabel::OBBase*, > std::map<std::string, std::string, std::less<std::string>, > std::allocator<std::pair<std::string const, std::string> > > const*, > OpenBabel::OBConversion*) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0xFF583: OpenBabel::OBMol::DoTransformations(std::map<std::string, > std::string, std::less<std::string>, std::allocator<std::pair<std::string > const, std::string> > > const*, OpenBabel::OBConversion*) (in > /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x1081DC: > OpenBabel::OBMoleculeFormat::ReadChemObjectImpl(OpenBabel::OBConversion*, > OpenBabel::OBFormat*) (in /opt/openbabel-2.3.1/lib/libopenbabel.4.0.1.dylib) > by 0x6BD8A3: > OpenBabel::OBMoleculeFormat::ReadChemObject(OpenBabel::OBConversion*) (in > /opt/openbabel-2.3.1/lib/openbabel/2.3.1/abinitformat.so) So, it happens when OpFillUC::Do calls OBAtom::Duplicate, which in turn tries to do a lot of things that look, well, clever. The code in question is from src/ops/fillUC.cpp: OBAtom *newAtom = pmol->NewAtom(); newAtom->Duplicate(atom->first); newAtom->SetVector( pUC->FractionalToCartesian(atom->second[i])); where atom->first is an OBAtom* (the original atom) and atom->second[i] is a vector3 (the coordinates). I'm seeing the same kind of code in src/generic.cpp's OBUnitCell::FillUnitCell: newAtom = mol->NewAtom(); newAtom->Duplicate(*i); newAtom->SetVector(FractionalToCartesian(updatedCoordinate)); So, that leaves me wondering: 1. Why is atom duplication doing a "deep copy" (trying to infer properties it doesn't know), and not a "shallow copy"? Is there a way to perform the latter instead? (I look at OBAtom's methods, but couldn't find anything) 2. Even if it does try to figure out atomic partial charges, why does it lead to a memory mishandling? I hope someone can help me with that issue. If you want to play around with it, just run "babel --fillUC AFO.cif AFO.pdb" on the attached AFO.cif file. Many thanks in advance, FX
AFO.cif
Description: Binary data
------------------------------------------------------------------------------ Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss