tclblend - potential memory leak
Brought to you by:
mdejong
If SetJavaCmdFromAny (javaObj.c) is invoked for a command referencing a java object then the Tcl_Obj's typePtr is set to null before calling SetCmdNameFromAny which prevents it calling the Tcl_Obj 's freeIntRepProc and thus deleting the the java object. However a "commandname" Tcl_Obj will already have its internalRep.twoPtrValue.ptr1 set to a malloc'ed ResolvedCmdName structure, which is not released before being set to a new malloc'ed ResolvedCmdName structure. This happens when Tcl_GetCommandFromObj() forces another conversion due to change in namespace
tclBlend 1.4.1
tcl8.4.19
Itcl3.4
Java 1.4/1.5/6
solaris 10, hpux 11, redhat 3/4/5
example to demonstrate bug
Uploaded memtest.tcl to demonstrate the bug.
Run the script and it prompts for input "A" or "B".
Enter A and monitor process for 10 - 20 seconds. This test creates java objects in namespace A and executes the resulting commands also in namespace A. Process size inreases and then remains constant.
Re-run and enter B, This test creates java objects in namespace A and executes and executes the resulting commands in namespace B. Monitoring the process show its size continually increasing.
Process needs to be manually terminated
Minimal test case:
namespace eval B {
proc run {obj} {
# if variable is treated as a command in this namespace the
# ResolvedCmdName is regenerated, but the previous is not released.
$obj toString
}
}
set obj [java::new String "foo"]
$obj toString
B::run $obj
set obj ""
Created Patch 2982514