[Mesa-users] Fixed many memory leaks
Zhang, Zhaoxi M. (Michael)
mz at astro.caltech.edu
Tue Apr 10 15:51:00 EDT 2018
Hello everyone,
I'm running into a problem where if I leave a model running for too long with diffusion enabled, MESA takes up more and more memory, eventually getting killed by the operating system because the system runs out of memory. I used valgrind to check for memory leaks, and found the cause of these problems. A patch is attached.
There are many areas of the code that look like this:
call do_alloc
call do_step_1(..., ..., ierr)
if (ierr /= 0) return
call do_step_2(..., ..., ierr)
if (ierr /= 0) return
call dealloc
If any of the steps between do_alloc and dealloc encounter an error, the subroutine returns without freeing the allocated memory. In my case, "fixup" often fails in diffusion, leading to a constant stream of leaks.
The patch doesn't fix all the potential memory leaks. If do_alloc ever fails, the function returns without calling dealloc. If do_alloc succeeds in allocating some but not all of the arrays, it might be dangerous to call dealloc because it might try to free unallocated arrays.
valgrind also detected one other definite memory leak and 2 probable ones, but they seem to be small one-time leaks relating to MESA's startup routines. The definite memory leak is probably because Free_Kap_CO_Tables is never called, but I don't know for sure. I've attached valgrind's output in case someone wants to try finding the leak.
Cheers,
Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20180410/d6e9a6f7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memory_leak_patch
Type: application/octet-stream
Size: 6998 bytes
Desc: memory_leak_patch
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20180410/d6e9a6f7/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: other_memory_leaks
Type: application/octet-stream
Size: 3036 bytes
Desc: other_memory_leaks
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20180410/d6e9a6f7/attachment-0001.obj>
More information about the Mesa-users
mailing list