XTCFormat::ReadMolecule() used to pass a pointer to the storage of a local
std::vector to OBMol::SetConformers() after the vector itself was destroyed.
This leads to OBMol::_vconf pointing to freed memory, reading garbage
(as mentioned previously in 
http://forums.openbabel.org/Reading-XTC-format-does-not-seem-to-work-tp3675197p3733137.html
 ) and finally a crash when the memory is freed for the
second time by OBMol's ~OBMol() or SetConformers().

There's no reason to use a std::vector here when one doesn't want its
automatic lifetime management.
---
 src/formats/xtcformat.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/formats/xtcformat.cpp b/src/formats/xtcformat.cpp
index c58b2b4..c2bcaaa 100644
--- a/src/formats/xtcformat.cpp
+++ b/src/formats/xtcformat.cpp
@@ -184,12 +184,11 @@ namespace OpenBabel
 
       // Convert positions from single to double precision and convert from
       // nm to A
-      std::vector<double> confs;
-      confs.resize(natoms * 3);
+      double* confs = new double[natoms * 3];
       for (int i=0; i < natoms * 3; ++i) // unroll??
         confs[i] = static_cast<double>(10.0 * floatCoord.at(i));
 
-      vconf.push_back(&confs[0]);
+      vconf.push_back(confs);
     }
 
     // Close the XDR file
-- 
1.9.3

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to