Closed NullCGT closed 2 years ago
A more detailed trace, obtained after compiling the debug version:
==20372== HEAP SUMMARY:
==20372== in use at exit: 25,860 bytes in 862 blocks
==20372== total heap usage: 1,103 allocs, 241 frees, 79,382,248 bytes allocated
==20372==
==20372== Searching for pointers to 862 not-freed blocks
==20372== Checked 114,800 bytes
==20372==
==20372== 1,500 (600 direct, 900 indirect) bytes in 25 blocks are definitely lost in loss record 2 of 8
==20372== at 0x4845899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20372== by 0x12A232: wfc_img_create (wfc.h:382)
==20372== by 0x12B243: wfc__create_tile_image (wfc.h:670)
==20372== by 0x12B395: wfc__add_overlapping_images (wfc.h:697)
==20372== by 0x12C8C6: wfc__create_tiles_overlapping (wfc.h:1207)
==20372== by 0x12CB07: wfc_overlapping (wfc.h:1279)
==20372== by 0x12D595: main (wfctool.c:218)
==20372==
==20372== 3,060 (1,224 direct, 1,836 indirect) bytes in 51 blocks are definitely lost in loss record 4 of 8
==20372== at 0x4845899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20372== by 0x12A128: wfc_img_copy (wfc.h:359)
==20372== by 0x12A6AA: wfc__img_flip_horizontally (wfc.h:479)
==20372== by 0x12B473: wfc__add_flipped_images (wfc.h:720)
==20372== by 0x12C8F4: wfc__create_tiles_overlapping (wfc.h:1212)
==20372== by 0x12CB07: wfc_overlapping (wfc.h:1279)
==20372== by 0x12D595: main (wfctool.c:218)
==20372==
==20372== 7,680 (3,072 direct, 4,608 indirect) bytes in 128 blocks are definitely lost in loss record 6 of 8
==20372== at 0x4845899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20372== by 0x12A232: wfc_img_create (wfc.h:382)
==20372== by 0x12AA5D: wfc__img_rotate90 (wfc.h:529)
==20372== by 0x12B588: wfc__add_rotated_images (wfc.h:746)
==20372== by 0x12C945: wfc__create_tiles_overlapping (wfc.h:1224)
==20372== by 0x12CB07: wfc_overlapping (wfc.h:1279)
==20372== by 0x12D595: main (wfctool.c:218)
==20372==
==20372== 13,620 (5,448 direct, 8,172 indirect) bytes in 227 blocks are definitely lost in loss record 8 of 8
==20372== at 0x4845899: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20372== by 0x12A232: wfc_img_create (wfc.h:382)
==20372== by 0x12AA39: wfc__img_rotate90 (wfc.h:527)
==20372== by 0x12B588: wfc__add_rotated_images (wfc.h:746)
==20372== by 0x12C945: wfc__create_tiles_overlapping (wfc.h:1224)
==20372== by 0x12CB07: wfc_overlapping (wfc.h:1279)
==20372== by 0x12D595: main (wfctool.c:218)
==20372==
==20372== LEAK SUMMARY:
==20372== definitely lost: 10,344 bytes in 431 blocks
==20372== indirectly lost: 15,516 bytes in 431 blocks
==20372== possibly lost: 0 bytes in 0 blocks
==20372== still reachable: 0 bytes in 0 blocks
==20372== suppressed: 0 bytes in 0 blocks
==20372==
==20372== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
Thanks for filing the issue, this is a great finding. I'll be looking into it asap. Are these traces obtained after a single wfc_run
or multiple runs?
I do dev on a mac m1 so it might be challenging to use valgrind.
Thank you for the fast response! This library is a fantastic resource, and I've been really enjoying working with it.
These stacktraces come from a single wfc_run()
, and occur both with and without contradictions. Based on the second stacktrace and what I saw when I looked into the codebase, it seems like the issue has to do with the creation of rotated and flipped images, which could mean that images created by wfc_image_copy()
are not being properly freed?
I've just merged a fix: https://github.com/krychu/wfc/pull/20. After all rotations and flips are done, there is a step which discards duplicate tiles. These duplicates were not freed properly. Your hints and report were very useful in tracking this down. Thanks a lot!
I've made a couple of runs with different configurations and input images and am not seeing more leaks. Let me know if this looks good on your end.
Thanks again, and great to see the library being useful! Feel free to share where / how you use the lib. It's very rewarding :)
I was running valgrind on a project that I am using this library in, and I noticed some significant memory leakage. I ended up trying the same thing with the sample program, and noticed leaking memory there as well. I'm still trying to track down the exact issue, but it looks like the memory allocated for the wfc struct is not properly freed when wfc_destroy() is called. This occurs both during contradiction and successful output creation.
Valgrind output: