vincefn / objcryst

Free Objects for Crystallography : Fox / ObjCryst++
Other
23 stars 10 forks source link

Fix leak in CrystVector reported by valgrind #38

Closed pavoljuhas closed 6 years ago

pavoljuhas commented 6 years ago

I have tested libdiffpy linked with ObjCryst with valgrind and it reported some leaks in CrystVector. This should address that.


Problem: Copy constructor of CrystVector allocates zero-length buffer, but resize() method does not delete it. https://github.com/vincefn/objcryst/blob/65ab262c33f7528f26f6dac1ff1a1103e7b2099d/ObjCryst/CrystVector/CrystVector.cpp#L58-L61

Solution: Always delete the old buffer unless a reference. The pointer for unallocated buffer is NULL so its deletion is safe.

vincefn commented 6 years ago

Sorry I had not seen this pull request before