Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible memleak: defer putlog() from dns threads to main thread #1557

Merged
merged 6 commits into from
May 5, 2024

Conversation

michaelortmann
Copy link
Member

@michaelortmann michaelortmann commented Apr 1, 2024

Found by: if it fixes #1545 then Mystery-X else michaelortmann
Patch by: michaelortmann
Fixes: could fix #1545

One-line summary:
Fix possible memory leak: defer debug() / putlog() from dns threads to main thread via dtn.strerror

Additional description (if needed):
valgrind doesnt like

Test cases demonstrating functionality (if applicable):
Test 1: 1 error in dnslookup leaks 144 bytes

$ valgrind --leak-check=full ./eggdrop -t BotA.conf
.tcl dnslookup foo bar
.die
==619111== 144 (16 direct, 128 indirect) bytes in 1 blocks are definitely lost in loss record 375 of 543
==619111==    at 0x4843788: malloc (vg_replace_malloc.c:442)
==619111==    by 0x49A36DA: TSDTableCreate (tclThreadStorage.c:88)
==619111==    by 0x49A36DA: TclThreadStorageKeySet (tclThreadStorage.c:230)
==619111==    by 0x49A25DC: Tcl_GetThreadData (tclThread.c:92)
==619111==    by 0x4981DE3: TclFreeObj (tclObj.c:1444)
==619111==    by 0x49B1DD4: CleanupVar (tclVar.c:344)
==619111==    by 0x49B1DD4: TclPtrUnsetVarIdx (tclVar.c:2513)
==619111==    by 0x49B49E8: TclObjUnsetVar2 (tclVar.c:2386)
==619111==    by 0x49B4B16: Tcl_UnsetVar2 (tclVar.c:2338)
==619111==    by 0x153CF7: check_tcl_bind (tclhash.c:955)
==619111==    by 0x154F25: check_tcl_log (tclhash.c:1252)
==619111==    by 0x143998: putlog (misc.c:563)
==619111==    by 0x13A158: thread_dns_ipbyhost (dns.c:560)
==619111==    by 0x51ED559: start_thread (pthread_create.c:447)

Test 2: 2 errors in (2) dnslookup leaks 288 bytes, so its scaling ouch

$ valgrind --leak-check=full ./eggdrop -t BotA.conf
.tcl dnslookup foo bar
.tcl dnslookup foo bar
.die
==658361== 288 (32 direct, 256 indirect) bytes in 2 blocks are definitely lost in loss record 402 of 543
==658361==    at 0x4843788: malloc (vg_replace_malloc.c:442)
==658361==    by 0x49A36DA: TSDTableCreate (tclThreadStorage.c:88)
==658361==    by 0x49A36DA: TclThreadStorageKeySet (tclThreadStorage.c:230)
==658361==    by 0x49A25DC: Tcl_GetThreadData (tclThread.c:92)
==658361==    by 0x4981DE3: TclFreeObj (tclObj.c:1444)
==658361==    by 0x49B1DD4: CleanupVar (tclVar.c:344)
==658361==    by 0x49B1DD4: TclPtrUnsetVarIdx (tclVar.c:2513)
==658361==    by 0x49B49E8: TclObjUnsetVar2 (tclVar.c:2386)
==658361==    by 0x49B4B16: Tcl_UnsetVar2 (tclVar.c:2338)
==658361==    by 0x153CF7: check_tcl_bind (tclhash.c:955)
==658361==    by 0x154F25: check_tcl_log (tclhash.c:1252)
==658361==    by 0x143998: putlog (misc.c:563)
==658361==    by 0x13A158: thread_dns_ipbyhost (dns.c:560)
==658361==    by 0x51ED559: start_thread (pthread_create.c:447)

gccs LeakSanitizer also finds it, but valgrinds report is more detailed

@vanosg vanosg added this to the v1.10.0 milestone May 5, 2024
@vanosg vanosg merged commit d0d0754 into eggheads:develop May 5, 2024
2 checks passed
@michaelortmann michaelortmann deleted the tdns.thread.putlog branch May 6, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eggdrop 1.9.5 - Possible memory leak in botnet communication?
2 participants