Fix memory leaks and uninitialized memory access - #5108
Merged
Conversation
FixNVESpin::init() runs once per run command, so every run after the first orphaned the previous rsec allocation.
The second pass assigns fp only for those local densities that apply to the type of the central atom, but the force loop reads all of them, so the array must be zeroed first. The non-threaded pair style does this already.
A second pair_coeff command orphaned the entire set of tabulated arrays.
…g them A second pair_style command leaked the previous generator: randomT in pair style edpd, random in pair style sdpd/taitwater/isothermal.
The constructors declared a local variable of the same name, so the member stayed uninitialized until the first compute, while memory_usage() reads it as early as the first thermo output.
…the grid ngrid is set by allocate(), which ran after the statistics were printed, so the reported number of 3d grid values was undefined on the first run. Both PPPM and PPPMDipole have these two blocks in the opposite order.
Atoms without an entry in the Ellipsoids section kept an undefined radius, which was then written to restart and dump files.
write_restart_settings() stores all 100 entries, not only those set with the ecp keyword, so it wrote undefined data to the restart file.
Clearing input->arg orphaned the argument list that Input frees on delete.
Memory that is still reachable when the process exits is not a leak. Those reports bury the actual defects under thousands of one-time initializations in OpenSSL, libcurl, CPython and GoogleTest and under everything that is still in use when a command like quit terminates the process on purpose. MEMORYCHECK_COMMAND_OPTIONS is a cache variable, so existing build folders keep their current setting and have to be updated explicitly with cmake -D MEMORYCHECK_COMMAND_OPTIONS="..." <builddir>
6 tasks
akohlmey
marked this pull request as ready for review
July 26, 2026 15:36
jrgissing
approved these changes
Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request addresses issues found from running
ctest -T memcheck.Related Issue(s)
N/A
Author(s)
Axel Kohlmeyer, Temple U
Licensing
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Artificial Intelligence (AI) Tools Usage
Claude Code Opus 5 assisted in analyzing the output from the test run and suggested individual fixes.
Backward Compatibility
Yes.
Implementation Notes
A lot of false positives can be avoided by using an improved valgrind command line.
This is included in the CMake configuration and described in
tools/valgrind/README.Post Submission Checklist
system