PlutoLang / Pluto

A superset of Lua 5.4 with a focus on general-purpose programming.
https://pluto-lang.org
MIT License
359 stars 22 forks source link

Valgrind warnings #619

Closed mingodad closed 8 months ago

mingodad commented 8 months ago
valgrind pluto fibonacci.lua 
==4418== Memcheck, a memory error detector
==4418== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4418== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==4418== Command: pluto fibonacci.lua
==4418== 
==4418== Conditional jump or move depends on uninitialised value(s)
==4418==    at 0x19A381: luaK_posfix(FuncState*, BinOpr, expdesc*, expdesc*, int) (lcode.cpp:1829)
==4418==    by 0x136FB5: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3438)
==4418==    by 0x136F7F: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3437)
==4418==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4418==    by 0x133D51: primaryexp(LexState*, expdesc*) (lparser.cpp:2671)
==4418==    by 0x133EC1: suffixedexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:2707)
==4418==    by 0x136094: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3210)
==4418==    by 0x13688B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3369)
==4418==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4418==    by 0x1314A7: explist(LexState*, expdesc*, TypeHint*) (lparser.cpp:2136)
==4418==    by 0x13795F: restassign(LexState*, LHS_assign*, int) (lparser.cpp:3619)
==4418==    by 0x13B4EE: exprstat(LexState*) (lparser.cpp:4393)
==4418== 
3524578
==4418== 
==4418== HEAP SUMMARY:
==4418==     in use at exit: 0 bytes in 0 blocks
==4418==   total heap usage: 754 allocs, 754 frees, 167,125 bytes allocated
==4418== 
==4418== All heap blocks were freed -- no leaks are possible
==4418== 
==4418== Use --track-origins=yes to see where uninitialised values come from
==4418== For lists of detected and suppressed errors, rerun with: -s
==4418== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0)

fibonacci.lua :

local function fib(n)
    if (n < 2) then 
    return 1
    else
    return fib(n-2) + fib(n-1)
    end
end

print(fib(32))
Sainan commented 8 months ago

The linked PR should fix this.

mingodad commented 8 months ago

And when trying to execute the code shown bellow from https://github.com/pygy/LuLPeg.git. https://github.com/pygy/LuLPeg/tests/luagrammar.lua :

valgrind pluto luagrammar.lua 
==4660== Memcheck, a memory error detector
==4660== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==4660== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==4660== Command: pluto luagrammar.lua
==4660== 
==4660== Conditional jump or move depends on uninitialised value(s)
==4660==    at 0x19A381: luaK_posfix(FuncState*, BinOpr, expdesc*, expdesc*, int) (lcode.cpp:1829)
==4660==    by 0x136FB5: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3438)
==4660==    by 0x136F7F: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3437)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660==    by 0x133D51: primaryexp(LexState*, expdesc*) (lparser.cpp:2671)
==4660==    by 0x133EC1: suffixedexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:2707)
==4660==    by 0x136094: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3210)
==4660==    by 0x13688B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3369)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660==    by 0x1314A7: explist(LexState*, expdesc*, TypeHint*) (lparser.cpp:2136)
==4660==    by 0x13795F: restassign(LexState*, LHS_assign*, int) (lparser.cpp:3619)
==4660==    by 0x13B4EE: exprstat(LexState*) (lparser.cpp:4393)
==4660== 
==4660== Conditional jump or move depends on uninitialised value(s)
==4660==    at 0x19A381: luaK_posfix(FuncState*, BinOpr, expdesc*, expdesc*, int) (lcode.cpp:1829)
==4660==    by 0x136FB5: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3438)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660==    by 0x12E3C6: recfield(LexState*, ConsControl*, bool) (lparser.cpp:1439)
==4660==    by 0x12EA8B: field(LexState*, ConsControl*, bool) (lparser.cpp:1530)
==4660==    by 0x12ECCD: constructor(LexState*, expdesc*) (lparser.cpp:1580)
==4660==    by 0x131A87: funcargs(LexState*, expdesc*, TypeDesc*) (lparser.cpp:2211)
==4660==    by 0x13436B: expsuffix(LexState*, expdesc*, int, int, TypeHint*) (lparser.cpp:2796)
==4660==    by 0x133F41: suffixedexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:2714)
==4660==    by 0x136094: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3210)
==4660==    by 0x13688B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3369)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660== 
==4660== Invalid read of size 1
==4660==    at 0x13ADE3: localstat(LexState*) (lparser.cpp:4301)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x141638: mainfunc(LexState*, FuncState*) (lparser.cpp:5301)
==4660==    by 0x141A09: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5358)
==4660==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==4660==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==4660==    by 0x12159F: luaD_pcall(lua_State*, void (*)(lua_State*, void*), void*, long, long) (ldo.cpp:953)
==4660==    by 0x1218A7: luaD_protectedparser(lua_State*, Zio*, char const*, char const*) (ldo.cpp:1018)
==4660==    by 0x11BB53: lua_load(lua_State*, char const* (*)(lua_State*, void*, unsigned long*), void*, char const*, char const*) (lapi.cpp:1214)
==4660==    by 0x170B19: luaL_loadfilex(lua_State*, char const*, char const*) (lauxlib.cpp:878)
==4660==    by 0x117217: handle_script(lua_State*, char**) (lua.cpp:264)
==4660==  Address 0x5eb72b9 is 793 bytes inside a block of size 896 free'd
==4660==    at 0x4C3812F: realloc (vg_replace_malloc.c:1649)
==4660==    by 0x17151D: l_alloc(void*, void*, unsigned long, unsigned long) (lauxlib.cpp:1096)
==4660==    by 0x126F3F: luaM_realloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:180)
==4660==    by 0x126FE6: luaM_saferealloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:194)
==4660==    by 0x126D87: luaM_growaux_(lua_State*, void*, int, int*, int, int, char const*) (lmem.cpp:115)
==4660==    by 0x12BC97: new_localvar(LexState*, TString*, int, TypeHint, bool) (lparser.cpp:653)
==4660==    by 0x13A838: localstat(LexState*) (lparser.cpp:4239)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x1309E1: body(LexState*, expdesc*, int, int, TypeDesc*) (lparser.cpp:2025)
==4660==    by 0x135E7C: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3177)
==4660==    by 0x13688B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3369)
==4660==  Block was alloc'd at
==4660==    at 0x4C3812F: realloc (vg_replace_malloc.c:1649)
==4660==    by 0x17151D: l_alloc(void*, void*, unsigned long, unsigned long) (lauxlib.cpp:1096)
==4660==    by 0x126F3F: luaM_realloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:180)
==4660==    by 0x126FE6: luaM_saferealloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:194)
==4660==    by 0x126D87: luaM_growaux_(lua_State*, void*, int, int*, int, int, char const*) (lmem.cpp:115)
==4660==    by 0x12BC97: new_localvar(LexState*, TString*, int, TypeHint, bool) (lparser.cpp:653)
==4660==    by 0x13A838: localstat(LexState*) (lparser.cpp:4239)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x141638: mainfunc(LexState*, FuncState*) (lparser.cpp:5301)
==4660==    by 0x141A09: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5358)
==4660==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==4660== 
==4660== Conditional jump or move depends on uninitialised value(s)
==4660==    at 0x19A381: luaK_posfix(FuncState*, BinOpr, expdesc*, expdesc*, int) (lcode.cpp:1829)
==4660==    by 0x136FB5: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3438)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660==    by 0x1314A7: explist(LexState*, expdesc*, TypeHint*) (lparser.cpp:2136)
==4660==    by 0x13795F: restassign(LexState*, LHS_assign*, int) (lparser.cpp:3619)
==4660==    by 0x13B4EE: exprstat(LexState*) (lparser.cpp:4393)
==4660==    by 0x13E2A9: statement(LexState*, TypeHint*) (lparser.cpp:4933)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x141638: mainfunc(LexState*, FuncState*) (lparser.cpp:5301)
==4660==    by 0x141A09: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5358)
==4660==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==4660==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==4660== 
==4660== Conditional jump or move depends on uninitialised value(s)
==4660==    at 0x19A381: luaK_posfix(FuncState*, BinOpr, expdesc*, expdesc*, int) (lcode.cpp:1829)
==4660==    by 0x136FB5: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3438)
==4660==    by 0x136F7F: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3437)
==4660==    by 0x136F7F: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3437)
==4660==    by 0x137053: expr(LexState*, expdesc*, TypeHint*, int) (lparser.cpp:3449)
==4660==    by 0x130FAA: expr_propagate(LexState*, expdesc*, TypeHint&) (lparser.cpp:2081)
==4660==    by 0x13173A: funcargs(LexState*, expdesc*, TypeDesc*) (lparser.cpp:2172)
==4660==    by 0x13436B: expsuffix(LexState*, expdesc*, int, int, TypeHint*) (lparser.cpp:2796)
==4660==    by 0x133F41: suffixedexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:2714)
==4660==    by 0x13B4B6: exprstat(LexState*) (lparser.cpp:4390)
==4660==    by 0x13E2A9: statement(LexState*, TypeHint*) (lparser.cpp:4933)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660== 
/home/mingo/dev/lua/Pluto/src/pluto: luagrammar.lua:5: could not loadnil
stack traceback:
    [C]: in function 'assert'
    luagrammar.lua:5: in main chunk
    [C]: in ?
==4660== 
==4660== HEAP SUMMARY:
==4660==     in use at exit: 0 bytes in 0 blocks
==4660==   total heap usage: 1,638 allocs, 1,638 frees, 487,037 bytes allocated
==4660== 
==4660== All heap blocks were freed -- no leaks are possible
==4660== 
==4660== Use --track-origins=yes to see where uninitialised values come from
==4660== For lists of detected and suppressed errors, rerun with: -s
==4660== ERROR SUMMARY: 10 errors from 5 contexts (suppressed: 0 from 0)
Sainan commented 8 months ago

Is this using the patch from the PR? Also looks like your usage of the "luagrammar" script is incomplete, as it requires a CLI argument.

mingodad commented 8 months ago

No it's not using the patch. And yes it's not supplying the needed argument but should have no Invalid read of size 1.

Sainan commented 8 months ago

That's not how Lua/Pluto works. Accessing a non-existent table index returns nil.

mingodad commented 8 months ago

Yes that's ok but should not internally try to access memory like this:

==4660== Invalid read of size 1
==4660==    at 0x13ADE3: localstat(LexState*) (lparser.cpp:4301)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x141638: mainfunc(LexState*, FuncState*) (lparser.cpp:5301)
==4660==    by 0x141A09: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5358)
==4660==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==4660==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==4660==    by 0x12159F: luaD_pcall(lua_State*, void (*)(lua_State*, void*), void*, long, long) (ldo.cpp:953)
==4660==    by 0x1218A7: luaD_protectedparser(lua_State*, Zio*, char const*, char const*) (ldo.cpp:1018)
==4660==    by 0x11BB53: lua_load(lua_State*, char const* (*)(lua_State*, void*, unsigned long*), void*, char const*, char const*) (lapi.cpp:1214)
==4660==    by 0x170B19: luaL_loadfilex(lua_State*, char const*, char const*) (lauxlib.cpp:878)
==4660==    by 0x117217: handle_script(lua_State*, char**) (lua.cpp:264)
==4660==  Address 0x5eb72b9 is 793 bytes inside a block of size 896 free'd
==4660==    at 0x4C3812F: realloc (vg_replace_malloc.c:1649)
==4660==    by 0x17151D: l_alloc(void*, void*, unsigned long, unsigned long) (lauxlib.cpp:1096)
==4660==    by 0x126F3F: luaM_realloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:180)
==4660==    by 0x126FE6: luaM_saferealloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:194)
==4660==    by 0x126D87: luaM_growaux_(lua_State*, void*, int, int*, int, int, char const*) (lmem.cpp:115)
==4660==    by 0x12BC97: new_localvar(LexState*, TString*, int, TypeHint, bool) (lparser.cpp:653)
==4660==    by 0x13A838: localstat(LexState*) (lparser.cpp:4239)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x1309E1: body(LexState*, expdesc*, int, int, TypeDesc*) (lparser.cpp:2025)
==4660==    by 0x135E7C: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3177)
==4660==    by 0x13688B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3369)
==4660==  Block was alloc'd at
==4660==    at 0x4C3812F: realloc (vg_replace_malloc.c:1649)
==4660==    by 0x17151D: l_alloc(void*, void*, unsigned long, unsigned long) (lauxlib.cpp:1096)
==4660==    by 0x126F3F: luaM_realloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:180)
==4660==    by 0x126FE6: luaM_saferealloc_(lua_State*, void*, unsigned long, unsigned long) (lmem.cpp:194)
==4660==    by 0x126D87: luaM_growaux_(lua_State*, void*, int, int*, int, int, char const*) (lmem.cpp:115)
==4660==    by 0x12BC97: new_localvar(LexState*, TString*, int, TypeHint, bool) (lparser.cpp:653)
==4660==    by 0x13A838: localstat(LexState*) (lparser.cpp:4239)
==4660==    by 0x13DEA1: statement(LexState*, TypeHint*) (lparser.cpp:4840)
==4660==    by 0x12DAC0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1265)
==4660==    by 0x141638: mainfunc(LexState*, FuncState*) (lparser.cpp:5301)
==4660==    by 0x141A09: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5358)
==4660==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
Sainan commented 8 months ago

I see. I will try Valgrind with this on my own.

Sainan commented 8 months ago

Fixed this warning in ee8cb1d4058562c7f779d23e41d8c5bec0b211e0

mingodad commented 8 months ago

Even after the latest fixes when executing testes/pluto _driver.pluto:

valgrind pluto _driver.pluto
==6335== Memcheck, a memory error detector
==6335== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==6335== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==6335== Command: pluto _driver.pluto
==6335== 
Welcome to the test suite.
Testing assertion library
Testing compound assignment.
...
testing traceback sizes
testing debug functions on chunk without debug info
==6335== Conditional jump or move depends on uninitialised value(s)
==6335==    at 0x1223A8: is_lua_vm_compatible(Proto const*) (ldump.cpp:223)
==6335==    by 0x12245A: luaU_dump(lua_State*, Proto const*, int (*)(lua_State*, void const*, unsigned long, void*), void*, int) (ldump.cpp:244)
==6335==    by 0x11BCA2: lua_dump(lua_State*, int (*)(lua_State*, void const*, unsigned long, void*), void*, int) (lapi.cpp:1237)
==6335==    by 0x176FFA: str_dump(lua_State*) (lstrlib.cpp:273)
==6335==    by 0x120686: precallC(lua_State*, StackValue*, int, int (*)(lua_State*)) (ldo.cpp:529)
==6335==    by 0x1209B4: luaD_precall(lua_State*, StackValue*, int) (ldo.cpp:595)
==6335==    by 0x16C8C2: luaV_execute(lua_State*, CallInfo*) (lvm.cpp:2269)
==6335==    by 0x120C3E: ccall(lua_State*, StackValue*, int, unsigned int) (ldo.cpp:637)
==6335==    by 0x120CB3: luaD_callnoyield(lua_State*, StackValue*, int) (ldo.cpp:655)
==6335==    by 0x11B860: lua_callk(lua_State*, int, int, long, int (*)(lua_State*, int, long)) (lapi.cpp:1140)
==6335==    by 0x172DE0: luaB_dofile(lua_State*) (lbaselib.cpp:488)
==6335==    by 0x120686: precallC(lua_State*, StackValue*, int, int (*)(lua_State*)) (ldo.cpp:529)
==6335== 
OK
testing functions and calls
...
mingodad commented 8 months ago

Also continuation of the above (it's taking a bit to complete) :

OK
testing syntax
+
testing short-circuit optimizations (0)
+
+
+
+
OK
==6335== Conditional jump or move depends on uninitialised value(s)
==6335==    at 0x13430A: expsuffix(LexState*, expdesc*, int, int, TypeHint*) (lparser.cpp:2785)
==6335==    by 0x133F51: suffixedexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:2716)
==6335==    by 0x13B4E6: exprstat(LexState*) (lparser.cpp:4393)
==6335==    by 0x13E2D9: statement(LexState*, TypeHint*) (lparser.cpp:4936)
==6335==    by 0x12DAD0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1267)
==6335==    by 0x1309F1: body(LexState*, expdesc*, int, int, TypeDesc*) (lparser.cpp:2027)
==6335==    by 0x139D8A: localfunc(LexState*) (lparser.cpp:4097)
==6335==    by 0x13DE8C: statement(LexState*, TypeHint*) (lparser.cpp:4839)
==6335==    by 0x12DAD0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1267)
==6335==    by 0x141668: mainfunc(LexState*, FuncState*) (lparser.cpp:5304)
==6335==    by 0x141A39: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5361)
==6335==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6335== 

 >>> testC not active: skipping opcode tests <<<

testing large tables
OK
testing tables, next, and for
mingodad commented 8 months ago

And end with this leak (in use at exit: 34,940,421 bytes in 166,500 blocks) :

testing RK
testing large programs (>64k)
+
OK
>>> closing state <<<

==6335== 
==6335== HEAP SUMMARY:
==6335==     in use at exit: 34,940,421 bytes in 166,500 blocks
==6335==   total heap usage: 18,261,767 allocs, 18,095,267 frees, 3,179,367,342 bytes allocated
==6335== 
==6335== LEAK SUMMARY:
==6335==    definitely lost: 15,405,770 bytes in 99,632 blocks
==6335==    indirectly lost: 19,528,980 bytes in 66,856 blocks
==6335==      possibly lost: 4,840 bytes in 9 blocks
==6335==    still reachable: 831 bytes in 3 blocks
==6335==         suppressed: 0 bytes in 0 blocks
==6335== Rerun with --leak-check=full to see details of leaked memory
==6335== 
==6335== Use --track-origins=yes to see where uninitialised values come from
==6335== For lists of detected and suppressed errors, rerun with: -s
==6335== ERROR SUMMARY: 85 errors from 2 contexts (suppressed: 0 from 0)
mingodad commented 8 months ago

Here is the output when executing this project https://github.com/facebook/CParser.git that show several leaks and it's source :

valgrind --leak-check=full pluto cparser.lua testmacro-lua.c
==6947== Memcheck, a memory error detector
==6947== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==6947== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==6947== Command: pluto cparser.lua testmacro-lua.c
==6947== 
cparser.lua:717: warning: duplicate local declaration [var-shadow]
    717 | local ti = function()
        | ^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 709.
cparser.lua:721: warning: duplicate local declaration [var-shadow]
    721 | local ti = function()
        | ^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 717.
cparser.lua:740: warning: duplicate local declaration [var-shadow]
    740 | local ti = function() tok,n=ti() return tok,n end
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 721.
cparser.lua:743: warning: duplicate local declaration [var-shadow]
    743 | local function collectArgument(ti, varargs)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 740.
cparser.lua:745: warning: duplicate local declaration [var-shadow]
    745 | local tokens = {}
        | ^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'tokens' on line 707.
cparser.lua:770: warning: duplicate local declaration [var-shadow]
    770 | local function collectArguments(ti,def,ntok,nn)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 740.
cparser.lua:795: warning: duplicate local declaration [var-shadow]
    795 | local function substituteArguments(options, def, nargs, n, inDirective)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'options' on line 707.
cparser.lua:795: warning: duplicate local declaration [var-shadow]
    795 | local function substituteArguments(options, def, nargs, n, inDirective)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'n' on line 739.
cparser.lua:926: warning: too many arguments [excessive-arguments]
    926 | ls = ls[1]:sub(2) .. tableConcat(ls, nil, 2)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 1 argument, got 3.
cparser.lua:938: warning: too many arguments [excessive-arguments]
    938 | expandMacros(options, nmacros, tokenize, processDirectives, nmacros, yieldMacroLines)
        | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 0 arguments, got 6.
cparser.lua:1096: warning: duplicate local declaration [var-shadow]
    1096 | local li = function() s,n=li() return s,n end
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'li' on line 1093.
cparser.lua:1179: warning: too many arguments [excessive-arguments]
    1179 | if args then args = "(" .. tableConcat(args,",") .. ")"  end
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 1 argument, got 2.
cparser.lua:1180: warning: too many arguments [excessive-arguments]
    1180 | xdebug(n, "define %s%s = %s", nam, args or "", tableConcat(def,' '))
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 1 argument, got 2.
cparser.lua:1186: warning: duplicate local declaration [var-shadow]
    1186 | local function ti() i=i+1 return v[i] end
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 1160.
cparser.lua:1205: warning: duplicate local declaration [var-shadow]
    1205 | local function doMacroLines(lines, stop)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'lines' on line 1092.
cparser.lua:1228: warning: duplicate local declaration [var-shadow]
    1228 | local lines = {}
         | ^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'lines' on line 1092.
cparser.lua:1240: warning: too many arguments [excessive-arguments]
    1240 | xdebug(nn, "defmacro %s(%s) =", nam, tableConcat(args,','))
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 1 argument, got 2.
cparser.lua:1250: warning: duplicate local declaration [var-shadow]
    1250 | local tok = pti()
         | ^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'tok' on line 1098.
cparser.lua:1281: warning: too many arguments [excessive-arguments]
    1281 | processDirectives(options, macros, eliminateComments, joinLines,
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 0 arguments, got 7.
cparser.lua:1293: warning: too many arguments [excessive-arguments]
    1293 | processDirectives(options, macros, eliminateComments, joinLines,
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: expected 0 arguments, got 7.
cparser.lua:1341: warning: duplicate local declaration [var-shadow]
    1341 | nmacros['defined'] = function(ti)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 1337.
cparser.lua:1342: warning: duplicate local declaration [var-shadow]
    1342 | local tok,n = ti()
         | ^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'tok' on line 1098.
cparser.lua:1342: warning: duplicate local declaration [var-shadow]
    1342 | local tok,n = ti()
         | ^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'n' on line 1094.
cparser.lua:1387: warning: duplicate local declaration [var-shadow]
    1387 | local ti = function(keepSpaces)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ti' on line 1385.
cparser.lua:1840: warning: duplicate local declaration [var-shadow]
    1840 | local function parenthesize(nam)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'nam' on line 1837.
cparser.lua:1843: warning: duplicate local declaration [var-shadow]
    1843 | local function insertword(word,nam)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'nam' on line 1837.
cparser.lua:1847: warning: duplicate local declaration [var-shadow]
    1847 | local function makelist(ty,sep)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ty' on line 1837.
cparser.lua:1867: warning: duplicate local declaration [var-shadow]
    1867 | local function insertqual(ty,nam)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'ty' on line 1837.
cparser.lua:1867: warning: duplicate local declaration [var-shadow]
    1867 | local function insertqual(ty,nam)
         | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ here: this shadows the initial declaration of 'nam' on line 1837.
/home/mingo/dev/lua/Pluto/src/pluto: syntax error: cparser.lua:2087: 'function' expected
    2087 | static     = 'sclass',
         | ^^^^^^^^^^^^^^^^^^^^^^ here: this is invalid syntax.
==6947== 
==6947== HEAP SUMMARY:
==6947==     in use at exit: 1,568,852 bytes in 3,594 blocks
==6947==   total heap usage: 11,685 allocs, 8,091 frees, 3,828,865 bytes allocated
==6947== 
==6947== 8 bytes in 1 blocks are definitely lost in loss record 1 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x158DA9: __gnu_cxx::new_allocator<unsigned long>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x15662F: std::allocator_traits<std::allocator<unsigned long> >::allocate(std::allocator<unsigned long>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x1520C5: std::_Vector_base<unsigned long, std::allocator<unsigned long> >::_M_allocate(unsigned long) (stl_vector.h:343)
==6947==    by 0x14C9E6: void std::vector<unsigned long, std::allocator<unsigned long> >::_M_realloc_insert<int>(__gnu_cxx::__normal_iterator<unsigned long*, std::vector<unsigned long, std::allocator<unsigned long> > >, int&&) (vector.tcc:440)
==6947==    by 0x1480AB: unsigned long& std::vector<unsigned long, std::allocator<unsigned long> >::emplace_back<int>(int&&) (vector.tcc:121)
==6947==    by 0x130004: parlist(LexState*, std::vector<std::pair<TString*, TString*>, std::allocator<std::pair<TString*, TString*> > >*, std::vector<unsigned long, std::allocator<unsigned long> >*, TString**) (lparser.cpp:1914)
==6947==    by 0x130356: body(LexState*, expdesc*, int, int, TypeDesc*) (lparser.cpp:1954)
==6947==    by 0x139D8A: localfunc(LexState*) (lparser.cpp:4097)
==6947==    by 0x13DE8C: statement(LexState*, TypeHint*) (lparser.cpp:4839)
==6947==    by 0x12DAD0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1267)
==6947==    by 0x141668: mainfunc(LexState*, FuncState*) (lparser.cpp:5304)
==6947== 
==6947== 24 bytes in 1 blocks are definitely lost in loss record 3 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x157E7C: __gnu_cxx::new_allocator<WarningConfig>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x155194: std::allocator_traits<std::allocator<WarningConfig> >::allocate(std::allocator<WarningConfig>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x150533: std::_Vector_base<WarningConfig, std::allocator<WarningConfig> >::_M_allocate(unsigned long) (stl_vector.h:343)
==6947==    by 0x14A5F8: void std::vector<WarningConfig, std::allocator<WarningConfig> >::_M_range_initialize<WarningConfig const*>(WarningConfig const*, WarningConfig const*, std::forward_iterator_tag) (stl_vector.h:1579)
==6947==    by 0x146A0B: std::vector<WarningConfig, std::allocator<WarningConfig> >::vector(std::initializer_list<WarningConfig>, std::allocator<WarningConfig> const&) (stl_vector.h:626)
==6947==    by 0x1438BD: LexState::LexState() (llex.h:369)
==6947==    by 0x14171D: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5312)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947==    by 0x12159F: luaD_pcall(lua_State*, void (*)(lua_State*, void*), void*, long, long) (ldo.cpp:953)
==6947==    by 0x1218A7: luaD_protectedparser(lua_State*, Zio*, char const*, char const*) (ldo.cpp:1018)
==6947== 
==6947== 24 bytes in 1 blocks are definitely lost in loss record 4 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x118436: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) (basic_string.tcc:219)
==6947==    by 0x11835B: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct_aux<char const*>(char const*, char const*, std::__false_type) (basic_string.h:251)
==6947==    by 0x11831E: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*) (basic_string.h:270)
==6947==    by 0x1182D0: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> >(char const*, std::allocator<char> const&) (basic_string.h:531)
==6947==    by 0x129003: throwerr(LexState*, char const*, char const*, int) (lparser.cpp:123)
==6947==    by 0x12915A: throwerr(LexState*, char const*, char const*) (lparser.cpp:128)
==6947==    by 0x129C33: error_expected(LexState*, int) (lparser.cpp:239)
==6947==    by 0x129E3E: check(LexState*, int) (lparser.cpp:290)
==6947==    by 0x12EABD: field(LexState*, ConsControl*, bool) (lparser.cpp:1536)
==6947==    by 0x12ECDD: constructor(LexState*, expdesc*) (lparser.cpp:1582)
==6947==    by 0x135DF0: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3170)
==6947== 
==6947== 121 bytes in 1 blocks are possibly lost in loss record 9 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x5196959: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32)
==6947==    by 0x5197304: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::push_back(char) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32)
==6947==    by 0x1A00A9: LexState::appendLineBuff(char) (llex.h:431)
==6947==    by 0x19D1EF: llex(LexState*, SemInfo*) (llex.cpp:591)
==6947==    by 0x19B9FF: luaX_setinput(lua_State*, LexState*, Zio*, TString*, int) (llex.cpp:247)
==6947==    by 0x1419EE: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5327)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947==    by 0x12159F: luaD_pcall(lua_State*, void (*)(lua_State*, void*), void*, long, long) (ldo.cpp:953)
==6947==    by 0x1218A7: luaD_protectedparser(lua_State*, Zio*, char const*, char const*) (ldo.cpp:1018)
==6947==    by 0x11BB53: lua_load(lua_State*, char const* (*)(lua_State*, void*, unsigned long*), void*, char const*, char const*) (lapi.cpp:1214)
==6947== 
==6947== 205 bytes in 1 blocks are definitely lost in loss record 15 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x5196959: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32)
==6947==    by 0x5198057: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_append(char const*, unsigned long) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.32)
==6947==    by 0x145712: Pluto::ErrorMessage::addGenericHere(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (lerrormessage.hpp:51)
==6947==    by 0x129012: throwerr(LexState*, char const*, char const*, int) (lparser.cpp:123)
==6947==    by 0x12915A: throwerr(LexState*, char const*, char const*) (lparser.cpp:128)
==6947==    by 0x129C33: error_expected(LexState*, int) (lparser.cpp:239)
==6947==    by 0x129E3E: check(LexState*, int) (lparser.cpp:290)
==6947==    by 0x12EABD: field(LexState*, ConsControl*, bool) (lparser.cpp:1536)
==6947==    by 0x12ECDD: constructor(LexState*, expdesc*) (lparser.cpp:1582)
==6947==    by 0x135DF0: simpleexp(LexState*, expdesc*, int, TypeHint*) (lparser.cpp:3170)
==6947==    by 0x13689B: subexpr(LexState*, expdesc*, int, TypeHint*, int) (lparser.cpp:3371)
==6947== 
==6947== 576 (64 direct, 512 indirect) bytes in 1 blocks are definitely lost in loss record 63 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x15B42D: __gnu_cxx::new_allocator<ParserContext*>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x159DF6: std::allocator_traits<std::allocator<ParserContext*> >::allocate(std::allocator<ParserContext*>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x157985: std::_Deque_base<ParserContext, std::allocator<ParserContext> >::_M_allocate_map(unsigned long) (stl_deque.h:634)
==6947==    by 0x154A5D: std::_Deque_base<ParserContext, std::allocator<ParserContext> >::_M_initialize_map(unsigned long) (stl_deque.h:707)
==6947==    by 0x15007D: std::_Deque_base<ParserContext, std::allocator<ParserContext> >::_Deque_base() (stl_deque.h:510)
==6947==    by 0x14A021: std::deque<ParserContext, std::allocator<ParserContext> >::deque() (stl_deque.h:915)
==6947==    by 0x1465AD: std::stack<ParserContext, std::deque<ParserContext, std::allocator<ParserContext> > >::stack<std::deque<ParserContext, std::allocator<ParserContext> >, void>() (stl_stack.h:157)
==6947==    by 0x1438DE: LexState::LexState() (llex.h:369)
==6947==    by 0x14171D: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5312)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947== 
==6947== 576 (64 direct, 512 indirect) bytes in 1 blocks are definitely lost in loss record 64 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x15B471: __gnu_cxx::new_allocator<ClassData*>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x159E2C: std::allocator_traits<std::allocator<ClassData*> >::allocate(std::allocator<ClassData*>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x157AEB: std::_Deque_base<ClassData, std::allocator<ClassData> >::_M_allocate_map(unsigned long) (stl_deque.h:634)
==6947==    by 0x154C77: std::_Deque_base<ClassData, std::allocator<ClassData> >::_M_initialize_map(unsigned long) (stl_deque.h:707)
==6947==    by 0x1500CB: std::_Deque_base<ClassData, std::allocator<ClassData> >::_Deque_base() (stl_deque.h:510)
==6947==    by 0x14A03D: std::deque<ClassData, std::allocator<ClassData> >::deque() (stl_deque.h:915)
==6947==    by 0x1465C9: std::stack<ClassData, std::deque<ClassData, std::allocator<ClassData> > >::stack<std::deque<ClassData, std::allocator<ClassData> >, void>() (stl_stack.h:157)
==6947==    by 0x1438F3: LexState::LexState() (llex.h:369)
==6947==    by 0x14171D: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5312)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947== 
==6947== 4,472 (104 direct, 4,368 indirect) bytes in 1 blocks are definitely lost in loss record 197 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x15C263: __gnu_cxx::new_allocator<std::__detail::_Hash_node_base*>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x15C0C7: std::allocator_traits<std::allocator<std::__detail::_Hash_node_base*> >::allocate(std::allocator<std::__detail::_Hash_node_base*>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x15BC6E: std::__detail::_Hashtable_alloc<std::allocator<std::__detail::_Hash_node<std::pair<TString const* const, void*>, false> > >::_M_allocate_buckets(unsigned long) (hashtable_policy.h:2134)
==6947==    by 0x15B760: std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_allocate_buckets(unsigned long) (hashtable.h:361)
==6947==    by 0x15A540: std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_rehash_aux(unsigned long, std::integral_constant<bool, true>) (hashtable.h:2123)
==6947==    by 0x15895C: std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_rehash(unsigned long, unsigned long const&) (hashtable.h:2102)
==6947==    by 0x155F8A: std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_insert_unique_node(unsigned long, unsigned long, std::__detail::_Hash_node<std::pair<TString const* const, void*>, false>*, unsigned long) (hashtable.h:1748)
==6947==    by 0x1515A3: std::pair<std::__detail::_Node_iterator<std::pair<TString const* const, void*>, false, false>, bool> std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_emplace<TString const*&, TypeHint*&>(std::integral_constant<bool, true>, TString const*&, TypeHint*&) (hashtable.h:1695)
==6947==    by 0x14BA25: std::pair<std::__detail::_Node_iterator<std::pair<TString const* const, void*>, false, false>, bool> std::_Hashtable<TString const*, std::pair<TString const* const, void*>, std::allocator<std::pair<TString const* const, void*> >, std::__detail::_Select1st, std::equal_to<TString const*>, std::hash<TString const*>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::emplace<TString const*&, TypeHint*&>(TString const*&, TypeHint*&) (hashtable.h:781)
==6947==    by 0x147A21: std::pair<std::__detail::_Node_iterator<std::pair<TString const* const, void*>, false, false>, bool> std::unordered_map<TString const*, void*, std::hash<TString const*>, std::equal_to<TString const*>, std::allocator<std::pair<TString const* const, void*> > >::emplace<TString const*&, TypeHint*&>(TString const*&, TypeHint*&) (unordered_map.h:389)
==6947==    by 0x12B6D5: get_global_prop(LexState*, TString const*) (lparser.cpp:548)
==6947== 
==6947== 248,038 (131,072 direct, 116,966 indirect) bytes in 1 blocks are definitely lost in loss record 240 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x157D29: __gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x154FE8: std::allocator_traits<std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocate(std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x150319: std::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_allocate(unsigned long) (stl_vector.h:343)
==6947==    by 0x19536E: void std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(__gnu_cxx::__normal_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) (vector.tcc:440)
==6947==    by 0x19490F: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >& std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::emplace_back<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) (vector.tcc:121)
==6947==    by 0x19B8A6: inclinenumber(LexState*) (llex.cpp:229)
==6947==    by 0x19CE71: llex(LexState*, SemInfo*) (llex.cpp:549)
==6947==    by 0x19B9FF: luaX_setinput(lua_State*, LexState*, Zio*, TString*, int) (llex.cpp:247)
==6947==    by 0x1419EE: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5327)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947== 
==6947== 528,376 (16,384 direct, 511,992 indirect) bytes in 1 blocks are definitely lost in loss record 241 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x1586CD: __gnu_cxx::new_allocator<void*>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x155B58: std::allocator_traits<std::allocator<void*> >::allocate(std::allocator<void*>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x1512B5: std::_Vector_base<void*, std::allocator<void*> >::_M_allocate(unsigned long) (stl_vector.h:343)
==6947==    by 0x14B716: void std::vector<void*, std::allocator<void*> >::_M_realloc_insert<void*>(__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, void*&&) (vector.tcc:440)
==6947==    by 0x147883: void*& std::vector<void*, std::allocator<void*> >::emplace_back<void*>(void*&&) (vector.tcc:121)
==6947==    by 0x12A937: new_typehint(LexState*) (lparser.cpp:443)
==6947==    by 0x130BA3: body(LexState*, expdesc*, int, int, TypeDesc*) (lparser.cpp:2040)
==6947==    by 0x139D8A: localfunc(LexState*) (lparser.cpp:4097)
==6947==    by 0x13DE8C: statement(LexState*, TypeHint*) (lparser.cpp:4839)
==6947==    by 0x12DAD0: statlist(LexState*, TypeHint*, bool) (lparser.cpp:1267)
==6947==    by 0x139929: test_then_block(LexState*, int*, TypeHint*) (lparser.cpp:4035)
==6947== 
==6947== 786,432 bytes in 1 blocks are definitely lost in loss record 242 of 242
==6947==    at 0x4C337DB: operator new(unsigned long) (vg_replace_malloc.c:472)
==6947==    by 0x159D1C: __gnu_cxx::new_allocator<Token>::allocate(unsigned long, void const*) (new_allocator.h:114)
==6947==    by 0x157815: std::allocator_traits<std::allocator<Token> >::allocate(std::allocator<Token>&, unsigned long) (alloc_traits.h:443)
==6947==    by 0x15474F: std::_Vector_base<Token, std::allocator<Token> >::_M_allocate(unsigned long) (stl_vector.h:343)
==6947==    by 0x14FDB2: void std::vector<Token, std::allocator<Token> >::_M_realloc_insert<Token>(__gnu_cxx::__normal_iterator<Token*, std::vector<Token, std::allocator<Token> > >, Token&&) (vector.tcc:440)
==6947==    by 0x149E69: Token& std::vector<Token, std::allocator<Token> >::emplace_back<Token>(Token&&) (vector.tcc:121)
==6947==    by 0x19BA34: luaX_setinput(lua_State*, LexState*, Zio*, TString*, int) (llex.cpp:249)
==6947==    by 0x1419EE: luaY_parser(lua_State*, Zio*, Mbuffer*, Dyndata*, char const*, int) (lparser.cpp:5327)
==6947==    by 0x121792: f_parser(lua_State*, void*) (ldo.cpp:1001)
==6947==    by 0x11F575: luaD_rawrunprotected(lua_State*, void (*)(lua_State*, void*), void*) (ldo.cpp:144)
==6947==    by 0x12159F: luaD_pcall(lua_State*, void (*)(lua_State*, void*), void*, long, long) (ldo.cpp:953)
==6947==    by 0x1218A7: luaD_protectedparser(lua_State*, Zio*, char const*, char const*) (ldo.cpp:1018)
==6947== 
==6947== LEAK SUMMARY:
==6947==    definitely lost: 934,381 bytes in 10 blocks
==6947==    indirectly lost: 634,350 bytes in 3,583 blocks
==6947==      possibly lost: 121 bytes in 1 blocks
==6947==    still reachable: 0 bytes in 0 blocks
==6947==         suppressed: 0 bytes in 0 blocks
==6947== 
==6947== For lists of detected and suppressed errors, rerun with: -s
==6947== ERROR SUMMARY: 11 errors from 11 contexts (suppressed: 0 from 0)
mingodad commented 8 months ago

And for comparison is the above script run with Lua-5.4 :

valgrind --leak-check=full lua-5.4 cparser.lua testmacro-lua.c
==7238== Memcheck, a memory error detector
==7238== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==7238== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==7238== Command: lua-5.4 cparser.lua testmacro-lua.c
==7238== 
==7238== 
==7238== HEAP SUMMARY:
==7238==     in use at exit: 3,738 bytes in 90 blocks
==7238==   total heap usage: 101 allocs, 11 frees, 8,722 bytes allocated
==7238== 
==7238== LEAK SUMMARY:
==7238==    definitely lost: 0 bytes in 0 blocks
==7238==    indirectly lost: 0 bytes in 0 blocks
==7238==      possibly lost: 0 bytes in 0 blocks
==7238==    still reachable: 3,738 bytes in 90 blocks
==7238==         suppressed: 0 bytes in 0 blocks
==7238== Reachable blocks (those to which a pointer was found) are not shown.
==7238== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==7238== 
==7238== For lists of detected and suppressed errors, rerun with: -s
==7238== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
mingodad commented 8 months ago

Interesting even Lua-5.4 is leaking some memory but Lua-5.3.5 doesn't:

lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

valgrind --leak-check=full lua cparser.lua testmacro-lua.c
==7326== Memcheck, a memory error detector
==7326== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==7326== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==7326== Command: lua cparser.lua testmacro-lua.c
==7326== 
==7326== 
==7326== HEAP SUMMARY:
==7326==     in use at exit: 0 bytes in 0 blocks
==7326==   total heap usage: 4,631 allocs, 4,631 frees, 631,422 bytes allocated
==7326== 
==7326== All heap blocks were freed -- no leaks are possible
==7326== 
==7326== For lists of detected and suppressed errors, rerun with: -s
==7326== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
mingodad commented 8 months ago

Also LuaJIT doesn't leak any memory:

valgrind --leak-check=full luajit cparser.lua testmacro-lua.c
==7402== Memcheck, a memory error detector
==7402== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==7402== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==7402== Command: luajit cparser.lua testmacro-lua.c
==7402== 
==7402== 
==7402== HEAP SUMMARY:
==7402==     in use at exit: 0 bytes in 0 blocks
==7402==   total heap usage: 13 allocs, 13 frees, 10,210 bytes allocated
==7402== 
==7402== All heap blocks were freed -- no leaks are possible
==7402== 
==7402== For lists of detected and suppressed errors, rerun with: -s
==7402== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)