Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2013-09-24
12:03 • Closed ticket [3383616fff]: memory leak in Tcl 8.6 for compiled locals with reso... artifact: 2b54070dbe user: dkf
2011-08-02
20:42 • Ticket [3383616fff]: 4 changes artifact: 9d4174919f user: ferrieux
18:34 • Ticket [3383616fff]: 4 changes artifact: 81cf71e480 user: gneumann
00:16 • Pending ticket [3383616fff]. artifact: 4ba9d62ae5 user: msofer
00:16 • Ticket [3383616fff]: 4 changes artifact: f83b6b8c86 user: msofer
2011-08-01
23:48 • Ticket [3383616fff]: 4 changes artifact: d0b2847978 user: msofer
21:19 • Ticket [3383616fff]: 3 changes artifact: 1744bec8cc user: dgp
10:46 • New ticket [3383616fff]. artifact: c73511de15 user: gneumann

memory leak in Tcl 8.6 for compiled locals with resolveInfo

Closed / Fixed3383616fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 13 years ago
Descriptionplain2011-08-01 10:46:11
Tcl 8.6b2 has a memory leak when re-bytecompiling procs. The cleanup-section in function TclProcCompileProc() (in file tclProc.c) iterates over "old" compiledLocals and frees it blindly (see below: ckfree(toFree)). However, the resolveInfo can contain data, and might point to to a deleteProc. i discovered the issue when using resolvers. The cleanup is handled correctly in TclProcCleanupProc() and in a similar way in InitResolvedLocals(). To ease maintenance one should factor out a common small c-function to handle the cleanup of compiled locals. The issue does not exist in Tcl 8.5.*. The following patch fixes the issue, and runs clean with valgrind.

-gustaf neumann
PS: i have submitted the bugreport already yesterday, but it did not show up so far. Maybe, there is something broken at sourceforge, so i try again. I hope, this will not generate a duplicate entry.

--- generic/tclProc.c-orig2011-07-31 18:16:22.000000000 +0200
+++ generic/tclProc.c2011-07-31 18:17:05.000000000 +0200
@@ -2063,6 +2063,15 @@
 CompiledLocal *toFree = clPtr;
 
 clPtr = clPtr->nextPtr;
+
+if (toFree->resolveInfo) {
+    if (toFree->resolveInfo->deleteProc) {
+toFree->resolveInfo->deleteProc(toFree->resolveInfo);
+    } else {
+ckfree(toFree->resolveInfo);
+    }
+}
+
 ckfree(toFree);
     }
     procPtr->numCompiledLocals = procPtr->numArgs;
dgp Ticket [3383616fff]: 3 changes [History diff]2011-08-01 21:19:28
msoferplain2011-08-01 23:48:41
Thanks! Would it be possible for you to prepare a leak test for the testsuite?
msoferplain2011-08-02 00:16:08
Committed to trunk; leaving open as reminder to add a test
msofer Pending ticket [3383616fff]. [History diff]2011-08-02 00:16:09
gneumannplain2011-08-02 18:34:06
Not sure, that i can. To reach this point, one needs C code. As far i can see there are currently no tests for Tcl_AddInterpResolvers() in the test suite at all. Furthermore, i am as well not sure, what's the recommend way to  write tests in C and integrate this with the tcl test suite.
ferrieuxplain2011-08-02 20:42:23
That sort of thing is done by extending tclTest.c and one of its ancillary files like tclTestObj.c.
dkf Closed ticket [3383616fff]. [History diff]2013-09-24 12:03:41
Log in (anonymous is fine) to add a comment.