Basic rules to avoid corruptions:
- CONST_LUA_OK must be followed by a lua_push* / lua_newtable
- CONST_LUA_ERROR must *not* be followed by a lua_push* / lua_newtable
Detailed information can be found at https://www.lua.org/manual/5.2/manual.html#lua_CFunction
Fixes:
==21577==
==21577== 1,080 bytes in 27 blocks are definitely lost in loss record 310 of 320
==21577== at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==21577== by 0x4B9AB5: snmp_create_message (snmp.c:37)
==21577== by 0x4BC10F: SNMP::send_snmp_request(char*, char*, bool, char**, unsigned int) (SNMP.cpp:62)
==21577== by 0x4932C6: ntop_snmp_batch_get(lua_State*) (Lua.cpp:2598)
==21577== by 0x556046: lj_BC_FUNCC (in /home/simone/ntopng/ntopng)
==21577== by 0x5454FC: lua_pcall (in /home/simone/ntopng/ntopng)
==21577== by 0x4E4EA4: LuaHandler::luaL_dofileM(bool) (LuaHandler.cpp:34)
==21577== by 0x4A01D5: __ntop_lua_handlefile(lua_State*, char*, bool) (Lua.cpp:6959)
==21577== by 0x4A105B: Lua::run_script(char*, NetworkInterface*) (Lua.cpp:7638)
==21577== by 0x4A7F30: ThreadedActivity::runScript(char*, NetworkInterface*) (ThreadedActivity.cpp:162)
==21577== by 0x4A7E3B: ThreadedActivity::runScript() (ThreadedActivity.cpp:130)
==21577== by 0x4A809D: ThreadedActivity::uSecDiffPeriodicActivityBody() (ThreadedActivity.cpp:190)
==25013==
==25013== 672 (168 direct, 504 indirect) bytes in 7 blocks are definitely lost in loss record 305 of 320
==25013== at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==25013== by 0x4BB3E9: push_state (asn1.c:417)
==25013== by 0x4BB6CC: asn1_parse_structure (asn1.c:494)
==25013== by 0x4BB613: asn1_parse_sequence (asn1.c:477)
==25013== by 0x4BA3BD: snmp_parse_message (snmp.c:229)
==25013== by 0x4BC6B0: SNMP::snmp_fetch_responses(lua_State*) (SNMP.cpp:176)
==25013== by 0x493353: ntop_snmp_read_responses(lua_State*) (Lua.cpp:2614)
==25013== by 0x556006: lj_BC_FUNCC (in /home/simone/ntopng/ntopng)
==25013== by 0x5454BC: lua_pcall (in /home/simone/ntopng/ntopng)
==25013== by 0x4E4E6A: LuaHandler::luaL_dofileM(bool) (LuaHandler.cpp:34)
==25013== by 0x4A019B: __ntop_lua_handlefile(lua_State*, char*, bool) (Lua.cpp:6959)
==25013== by 0x4A1021: Lua::run_script(char*, NetworkInterface*) (Lua.cpp:7638)
==25013== 316 bytes in 6 blocks are definitely lost in loss record 299 of 320
==25013== at 0x4C29BE3: malloc (vg_replace_malloc.c:299)
==25013== by 0x812A949: strdup (in /usr/lib64/libc-2.17.so)
==25013== by 0x4BA8B2: snmp_get_varbind_as_string (snmp.c:421)
==25013== by 0x4BC70E: SNMP::snmp_fetch_responses(lua_State*) (SNMP.cpp:179)
==25013== by 0x493353: ntop_snmp_read_responses(lua_State*) (Lua.cpp:2614)
==25013== by 0x556006: lj_BC_FUNCC (in /home/simone/ntopng/ntopng)
==25013== by 0x5454BC: lua_pcall (in /home/simone/ntopng/ntopng)
==25013== by 0x4E4E6A: LuaHandler::luaL_dofileM(bool) (LuaHandler.cpp:34)
==25013== by 0x4A019B: __ntop_lua_handlefile(lua_State*, char*, bool) (Lua.cpp:6959)
==25013== by 0x4A1021: Lua::run_script(char*, NetworkInterface*) (Lua.cpp:7638)
==25013== by 0x4A7EF6: ThreadedActivity::runScript(char*, NetworkInterface*) (ThreadedActivity.cpp:162)
==25013== by 0x4A7E01: ThreadedActivity::runScript() (ThreadedActivity.cpp:130)