jacobjma / PyQSTEM

A Python interface to the electron microscopy simulation program QSTEM
GNU General Public License v3.0
60 stars 30 forks source link

Fix crashes due to deallocation of pointers in the wrong order. #6

Closed schiotz closed 6 years ago

schiotz commented 6 years ago

First, the pointer to pointer was deallocated, then the underlying pointer (accessed through the now-deallocated and therefore invalid pointer).

AEljarrat commented 6 years ago

Hi everyone,

I've been using pyqstem for a while and never got any problems until recently, when I had to recompile it. I observed that some simulations that before ran perfectly now produced core dump error related with memory allocation. In these programs I was running fast pyqstem simulations in a loop.

After some tinkering I discovered that recreating que PyQSTEM object inside of the loop corrected these errors, but this also made the execution (dramatically) slower.

The fix proposed in this pull request has fixed the problem. I thus recommend considering the merge.

I write this hoping this will serve some purpose. Anyhow, thanks Jacob for this nice software, Alberto E.