fix qeq_reax memory leak

Hi Steve, Ray and other developers,

A few weeks ago I reported a memory leak in the fix_qeq_reax when calling lammps from an external driver code. While the patch posted on 11 Feb 2013

improved things I’m affraid the problem remains. I apologize for reporting the opposite after your corrections, but I just noticed the fact after running the code on a machine with much less RAM.

Anyways, the memory leak is still there (more subtle).

Attached the files that you need in order to reproduce the problem. The simple.cpp is based on the one you provide in the COUPLE dir.

I have verified this problem working with the 26May13 version of Lammps.


ffield.reax (7.78 KB)

simple.cpp (3.33 KB)

in.lammps_butadiene_O2 (382 Bytes)

atoms.input (652 Bytes)


After careful examination with Valgrind, reax/c has 13 memory blocks that are lost after a test run and qeq/reax is responsible for 2 of the 13. These 13 memory losts all originated from the smalloc function. It is very subtle as you mentioned, but at this point it is not clear to me how this should be fixed. I will let you know when I have a solution.


Thanks Ray. I looked at it myself but did not get too far. The problem (continuous memory allocation) comes when calling the fix qeq/reax in combination with pair_style reax/c. If one comments out the fix qeq/reax and forces
pair_style reax/c to “checkqeq no” then the continuous memory allocation seems to stop.

I look forward to your solution.




The attached routine should fix the problem. Please let me know if it works for you.


fix_qeq_reax.cpp (22.5 KB)


The routine works just fine. At least my overnight runs that had been showing the problem stopped crashing, and the total memory they use matches much better the number I get from computing by hand the total memory allocated by all arrays.

Thanks for your prompt and efficient assistance,