Overview
| Artifact ID: | a766c581be7b70f5a1b06c195f27095a9fae9f71 |
|---|---|
| Ticket: | 219397ffffffffffffffffffffffffffffffffff
Memory leak after Tcl_InvalidateStringRep |
| User & Date: | nobody on 2000-10-26 05:12:24 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
OriginalBugID: 6226 Bug Version: 8.3.2 SubmitDate: '2000-09-07' LastModified: '2000-09-08' Severity: MED Status: UnAssn Submitter: techsupp ChangedBy: ericm OS: Solaris OSVersion: 5.7 Machine: sun4u sparc SUNW,Ultra-5_10 FixedDate: '2000-10-25' ClosedDate: '2000-10-25' Name: Fabrice Pardo ReproducibleScript: 1) add lines to tclTest.c (see below) 2) change MEM_DEBUG_FLAGS option in Makefile to -DTCL_MEM_DEBUG 3) do a "make clean; make runtest" % history keep 0 % tolist {x y} 1 ; memory info ;# repeat, "current packets allocated" is growing % tolist {x y} 1 ; memory info ;# repeat, "current packets allocated" is not growing ######################## lines added to tclTest.c ######################## ... static intTesttolistObjCmd _ANSI_ARGS_((ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])); ... /*---------------------------------------------------------------------- * * TesttolistObjCmd -- * * This function implements a "tolist _list_ _invalStringFlag_" * command, similar to * "lrange _list_ 0 end" command when _invalStringFlag_ == 0, * with an added call to Tcl_InvalidateStringRep(_list_) * when _invalStringFlag_ == 1 * * Results: * The _list_ argument * * Side effects: * # take care on 1 or 2 spaces between x and y. * tolist {x y} 1 ;# undesireable memory grown in interactive mode * tolist {x y} 1 ;# no side effect * tolist {x t} 0 ;# no side effect * set l {x y} * tolist $x 1 ;# no side effect */ int TesttolistObjCmd(notUsed, interp, objc, objv) ClientData notUsed;/* Not used. */ Tcl_Interp *interp;/* Current interpreter. */ int objc;/* Number of arguments. */ register Tcl_Obj *CONST objv[];/* Argument objects. */ { Tcl_Obj *listPtr; Tcl_Obj **elemPtrs; int listLen, invalStringFlag, result; if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "list invalStringFlag"); return TCL_ERROR; } listPtr = objv[1]; result = Tcl_ListObjGetElements(interp, listPtr, &listLen, &elemPtrs); if (result != TCL_OK) { return result; } if (Tcl_GetBooleanFromObj(interp, objv[2], &invalStringFlag) != TCL_OK) { return TCL_ERROR; } if (invalStringFlag) { Tcl_InvalidateStringRep(listPtr); } Tcl_SetListObj(Tcl_GetObjResult(interp), listLen, elemPtrs); return TCL_OK; } ... Tcl_CreateObjCommand(interp, "tolist", TesttolistObjCmd, 0, NULL); ... ObservedBehavior: If an argument is converted to a list and if his internal string representation is invalidated, there is a memory leak if the internal string representation was not canonical (e.g. "x y" instead of "x y"). This is because TclReleaseLiteral procedure doesnt find the new string internal representation "x y" in his database. Is it a compiler bug, or an Object/Tcl_InvalidateStringRep insufficient documentation ? Comment from Paul Duffin (via comp.lang.tcl): There is no memory leak because the string is still reachable from the literal table. However, there may be a problem if the literal table can grow forever but it won't be a memory leak. e.g. if the following code could potentially add a thousand strings to the literal table (not sure if it does) which is 'leaked' as far as the application is concerned. set string a for {set i 0} {$i < 1000} {incr i} { eval puts $string append string a } -- 09/08/2000 ericm - foundin changed to: "obsolete: 8.3.2"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "nobody"
- subsystem changed to: "69. Other"
- title changed to: "Memory leak after Tcl_InvalidateStringRep"
- type changed to: "Bug"