hrszpuk / rvm

A simplistic bytecode virtual machine.
MIT License
4 stars 0 forks source link

Fix memory leak issues #26

Closed hrszpuk closed 9 months ago

hrszpuk commented 9 months ago

This is a pretty big leak :sleepy:

Valgrind output

==17666== HEAP SUMMARY:
==17666==     in use at exit: 1,256 bytes in 6 blocks
==17666==   total heap usage: 6 allocs, 0 frees, 1,256 bytes allocated
==17666== 
==17666== LEAK SUMMARY:
==17666==    definitely lost: 0 bytes in 0 blocks
==17666==    indirectly lost: 0 bytes in 0 blocks
==17666==      possibly lost: 0 bytes in 0 blocks
==17666==    still reachable: 1,256 bytes in 6 blocks
==17666==         suppressed: 0 bytes in 0 blocks
==17666== Rerun with --leak-check=full to see details of leaked memory
==17666== 
==17666== For lists of detected and suppressed errors, rerun with: -s
==17666== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[1]    17666 segmentation fault (core dumped)  valgrind ./rvm devtest
➜  bin git:(dev) valgrind --leak-check=full ./rvm devtest
==17739== Memcheck, a memory error detector
==17739== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==17739== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==17739== Command: ./rvm devtest
==17739== 
==17739== 
==17739== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==17739==  Bad permissions for mapped region at address 0x10B463
==17739==    at 0x4927BEB: strtok_r (strtok_r.c:72)
==17739==    by 0x1096DC: TranslateInstructions (translator.c:71)
==17739==    by 0x109452: main (main.c:60)
==17739== 
==17739== HEAP SUMMARY:
==17739==     in use at exit: 1,256 bytes in 6 blocks
==17739==   total heap usage: 6 allocs, 0 frees, 1,256 bytes allocated
==17739== 
==17739== LEAK SUMMARY:
==17739==    definitely lost: 0 bytes in 0 blocks
==17739==    indirectly lost: 0 bytes in 0 blocks
==17739==      possibly lost: 0 bytes in 0 blocks
==17739==    still reachable: 1,256 bytes in 6 blocks
==17739==         suppressed: 0 bytes in 0 blocks
==17739== Reachable blocks (those to which a pointer was found) are not shown.
==17739== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==17739== 
==17739== For lists of detected and suppressed errors, rerun with: -s
==17739== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[1]    17739 segmentation fault (core dumped)  valgrind --leak-check=full ./rvm devtest
➜  bin git:(dev) valgrind --leak-check=full --show-leak-kinds=all ./rvm devtest
==17786== Memcheck, a memory error detector
==17786== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==17786== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==17786== Command: ./rvm devtest
==17786== 
==17786== 
==17786== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==17786==  Bad permissions for mapped region at address 0x10B463
==17786==    at 0x4927BEB: strtok_r (strtok_r.c:72)
==17786==    by 0x1096DC: TranslateInstructions (translator.c:71)
==17786==    by 0x109452: main (main.c:60)
==17786== 
==17786== HEAP SUMMARY:
==17786==     in use at exit: 1,256 bytes in 6 blocks
==17786==   total heap usage: 6 allocs, 0 frees, 1,256 bytes allocated
==17786== 
==17786== 16 bytes in 1 blocks are still reachable in loss record 1 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x109ABE: CreateBuffer (buffer.c:10)
==17786==    by 0x109D64: CreateVM (vm.c:15)
==17786==    by 0x10943F: main (main.c:59)
==17786== 
==17786== 24 bytes in 1 blocks are still reachable in loss record 2 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x10A35E: CreateStack (stack.c:11)
==17786==    by 0x109D53: CreateVM (vm.c:14)
==17786==    by 0x10943F: main (main.c:59)
==17786== 
==17786== 32 bytes in 1 blocks are still reachable in loss record 3 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x109D45: CreateVM (vm.c:13)
==17786==    by 0x10943F: main (main.c:59)
==17786== 
==17786== 80 bytes in 1 blocks are still reachable in loss record 4 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x10A373: CreateStack (stack.c:12)
==17786==    by 0x109D53: CreateVM (vm.c:14)
==17786==    by 0x10943F: main (main.c:59)
==17786== 
==17786== 80 bytes in 1 blocks are still reachable in loss record 5 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x109AE7: CreateBuffer (buffer.c:13)
==17786==    by 0x109D64: CreateVM (vm.c:15)
==17786==    by 0x10943F: main (main.c:59)
==17786== 
==17786== 1,024 bytes in 1 blocks are still reachable in loss record 6 of 6
==17786==    at 0x4841828: malloc (vg_replace_malloc.c:442)
==17786==    by 0x48FA499: _IO_file_doallocate (filedoalloc.c:101)
==17786==    by 0x4909278: _IO_doallocbuf (genops.c:347)
==17786==    by 0x4909278: _IO_doallocbuf (genops.c:342)
==17786==    by 0x49073E7: _IO_file_overflow@@GLIBC_2.2.5 (fileops.c:745)
==17786==    by 0x4907EC6: _IO_new_file_xsputn (fileops.c:1244)
==17786==    by 0x4907EC6: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1197)
==17786==    by 0x48D9B61: __printf_buffer_flush_to_file (printf_buffer_to_file.c:59)
==17786==    by 0x48D9C23: __printf_buffer_to_file_done (printf_buffer_to_file.c:120)
==17786==    by 0x48E3E59: __vfprintf_internal (vfprintf-internal.c:1524)
==17786==    by 0x48D92FE: printf (printf.c:33)
==17786==    by 0x109430: main (main.c:58)
==17786== 
==17786== LEAK SUMMARY:
==17786==    definitely lost: 0 bytes in 0 blocks
==17786==    indirectly lost: 0 bytes in 0 blocks
==17786==      possibly lost: 0 bytes in 0 blocks
==17786==    still reachable: 1,256 bytes in 6 blocks
==17786==         suppressed: 0 bytes in 0 blocks
==17786== 
==17786== For lists of detected and suppressed errors, rerun with: -s
==17786== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
[1]    17786 segmentation fault (core dumped)  valgrind --leak-check=full --show-leak-kinds=all ./rvm devtest