quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Memory leak in qjsc generated c code: js_std_free_handlers not called on finish

Open chemwolf6922 opened this issue 4 years ago • 2 comments

To reproduce: run ./example/hello with valgrind:

==2521191== Memcheck, a memory error detector
==2521191== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2521191== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==2521191== Command: ./hello
==2521191== 
Hello World
==2521191== 
==2521191== HEAP SUMMARY:
==2521191==     in use at exit: 88 bytes in 1 blocks
==2521191==   total heap usage: 755 allocs, 754 frees, 68,500 bytes allocated
==2521191== 
==2521191== 88 bytes in 1 blocks are definitely lost in loss record 1 of 1
==2521191==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==2521191==    by 0x10F991: UnknownInlinedFun (quickjs-libc.c:3771)
==2521191==    by 0x10F991: main (hello.c:36)
==2521191== 
==2521191== LEAK SUMMARY:
==2521191==    definitely lost: 88 bytes in 1 blocks
==2521191==    indirectly lost: 0 bytes in 0 blocks
==2521191==      possibly lost: 0 bytes in 0 blocks
==2521191==    still reachable: 0 bytes in 0 blocks
==2521191==         suppressed: 0 bytes in 0 blocks
==2521191== 
==2521191== For lists of detected and suppressed errors, rerun with: -s
==2521191== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

"ts" is malloced in js_std_init_handlers. And it is leaked on exit. qjsc writes js_std_init_handlers in main_c_template1 but does not write js_std_free_handlers in main_c_template2.

chemwolf6922 avatar Oct 13 '21 06:10 chemwolf6922

Note: "exit" in this issue does not refer to exit().

chemwolf6922 avatar Oct 13 '21 06:10 chemwolf6922

This is a mirror of the official repository issues should be put on the mailing list

Rdna123 avatar Dec 03 '21 03:12 Rdna123

fixed

bellard avatar Dec 22 '23 10:12 bellard