Morpho-lang / morpho

The Morpho language 🦋. Morpho is a small embeddable language for scientific computing applications.
MIT License
30 stars 10 forks source link

Memory leaks #187

Closed joshichaitanya3 closed 1 year ago

joshichaitanya3 commented 1 year ago

Here are a few memory leaks that show up on the dev branch:

  1. File_readline (file.c:252): out needs to be bound
  2. Matrix_subr (matrix.c:790): out needs to be bound in the case where the argument is a number
  3. Matrix_getindex (matrix.c:600)
  4. List_getindex (veneer.c:1180)

(I couldn't figure out how 3 and 4 could be fixed right away, has to do with slicing, but here is the backtrace from valgrind for them:

==124822== at 0x483B723: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==124822== by 0x483E017: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==124822== by 0x1305FF: morpho_allocate (memory.c:42) ==124822== by 0x1548D5: object_new (object.c:118) ==124822== by 0x15883C: object_newmatrix (matrix.c:43) ==124822== by 0x158896: matrix_sliceconstructor (matrix.c:562) ==124822== by 0x11AF85: getslice (veneer.c:560) ==124822== by 0x1596E8: Matrix_getindex (matrix.c:600)

==124822== at 0x483B723: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==124822== by 0x483E017: realloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==124894== by 0x1305FF: morpho_allocate (memory.c:42) ==124894== by 0x1548D5: object_new (object.c:118) ==124894== by 0x155277: object_newlist (object.c:703) ==124894== by 0x117687: list_sliceconstructor (veneer.c:1099) ==124894== by 0x11AF85: getslice (veneer.c:560) ==124894== by 0x11B332: List_getindex (veneer.c:1180)

joshichaitanya3 commented 1 year ago

Found these by running the test suite locally with command = valgrind --leak-check=full morpho5 in test.py:19. Saving the output to a single text file and using Python to look for uppercase method names in the backtrace seems to be a nice way of finding leaks from Morpho functions.

@ConduitDan , let me know if you have thoughts on integrating this into the test suite.

joshichaitanya3 commented 1 year ago

Re-opening this, since #188 fixed the memory build-up issue with edge flipping, but other memory leaks still need to be looked at.