DrylandEcology / STEPWAT2

folder
4 stars 5 forks source link

Memory Issues in Gridded Mode #568

Open alexisBelt opened 9 months ago

alexisBelt commented 9 months ago

Using Valgrind on Ubuntu 22.04, gridded mode is showing many memory issues, including un-freed memory. The report shows a total heap usage of 157,404 allocated, but only 156,986 freed, and shows definitely lost: 397 bytes in 23 blocks. stepwatMemoryErrors.docx

alexisBelt commented 4 months ago

commit 07cf11e0ea7e2d53cd6c837c1ab8bf0815ad013e fixes all of the STEPWAT2 memory issues/leaks. A vast majority of the issues ended up being because of incorrectly allocating memory to dest->est_spp in copy_rgroup. gridCells[i][j]._Gwf had memory allocated that was never freed. Smort and Gmort were being assigned values past the point of the memory allocated to them. This was fixed by looping according to the groups' and species' max_age, and not by the global max age. killMaxage was referencing pointers that no longer had any value or memory. This was fixed using a placeholder so that the pointer was not referenced. Everything else was due to either reading past a pointer array by one or two, or searching through rgroups that had no established species.