Possible Bug in internal memory management of the Tcl_Obj *
Closed / Fixed218278ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:55:23
OriginalBugID: 3387 Bug
Version: 8.2.1
SubmitDate: '1999-11-05'
LastModified: '2000-02-25'
Severity: CRIT
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: Other
OSVersion: Redhat linux 6.1, Solaris 2.6
FixedDate: '2000-10-25'
ClosedDate: '2000-02-25'
Name:
Georgios Petasis
ReproducibleScript:
Make an extension (e.g. a dynamic library) using this code:
#### Start of Code...
/* Function: Bug */
int Bug( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *objv[]) {
Tcl_Channel File;
Tcl_Obj *LineObj, **elemPtrs;
char *Line;
int i, chars, listLen;
File = Tcl_OpenFileChannel(interp, "Temp.txt", "w", 0666);
if (File == NULL) return TCL_ERROR;
/* Write each given object 2 times... */
for (i=0; i<objc; i++) {
Tcl_WriteChars(File, Tcl_GetString(objv[i]), -1);
Tcl_WriteChars(File, "\n", 1);
Tcl_WriteChars(File, Tcl_GetString(objv[i]), -1);
Tcl_WriteChars(File, "\n", 1);
}
if (Tcl_Close(interp, File) != TCL_OK) return TCL_ERROR;
File = Tcl_OpenFileChannel(interp, "Temp.txt", "r", 0666);
if (File == NULL) return TCL_ERROR;
LineObj = Tcl_NewObj();
if (LineObj == NULL) {printf("out of memory\n"); exit;}
Tcl_IncrRefCount(LineObj); chars = 1;
while (chars > 0) {
Tcl_SetObjLength(LineObj, 0);// Empty object, but keep allocated space...
printf("now reading objects...\n");
chars = Tcl_GetsObj(File, LineObj); if (chars<0 || Tcl_Eof(File))
break;
Line = Tcl_GetString(LineObj);
i = Tcl_ListObjGetElements(interp, LineObj, &listLen, &elemPtrs);
if (i == TCL_OK) {
printf("list: %s\n", Tcl_GetString(LineObj));
Tcl_SetListObj(LineObj, 0, NULL); /* Empty List obj */
}
else printf("string: %s\n", Tcl_GetString(LineObj));
printf("now reading chars...\n");
chars = Tcl_ReadChars(File, LineObj, strlen(Tcl_GetString(LineObj)),
0);
if (chars<0 || Tcl_Eof(File)) break;
chars = Tcl_ReadChars(File, LineObj, 1, 1); /* read new-line */
i = Tcl_ListObjGetElements(interp, LineObj, &listLen, &elemPtrs);
if (i == TCL_OK) {
printf("list: %s\n", Tcl_GetString(LineObj));
Tcl_SetListObj(LineObj, 0, NULL); /* Empty List obj */
}
else printf("string: %s\n", Tcl_GetString(LineObj));
}
printf("Now the core...\n");
if (Tcl_Close(interp, File) != TCL_OK) return TCL_ERROR;
Tcl_DecrRefCount(LineObj);
printf("Still Alive???????????????\n");
return TCL_OK;
} /* Bug */
## End of Code...
and inside tcl invoke the command with a quite lengthy list: a "Bug
[info commands]" will do the trick...
ObservedBehavior:
Seems that Tcl has problem using Tcl_SetListObj and Tcl_SetObjLength on
the same
object. When trying to free that object it crashes. In this small
example, Tcl crashes while
processing the list, but in my application It crashes when closing the
file (in Tcl_Eventually_Free something
inside Tcl_Close). In this litlle program it crashes inside
Tcl_ReadChars:
#0 0xef5ebec4 in SetStringFromAny ()
#1 0xef5eb638 in Tcl_SetObjLength ()
#2 0xef5d0ba8 in Tcl_ReadChars ()
Using 2 different objects solves the problem (at least in this small
example).
I think that this small example may not catch the entire problem (but it
may be a good start...)
My application still crashes when tries to free some objects that hold
lists
(created with Tcl_NewListObj) and have as elements other lists. All
items created
with Tcl_NewListObj and accessed/modified only through Tcl_***
functions. I really cannot
understand why tcl crashes...
DesiredBehavior:
The same Tcl_obj be used either as a list or as a string without
problem. I mean that the man
pages do not say that on object should be used only as a string or as a
list... Is that correct?
Could be related to Tcl_UnstackChannel bug fix from Andreas
Kupries (not yet applied).
-- 11/09/1999 hobbs
Not verifiable by someone one the net
http://www.deja.com/=dnc/viewthread.xp?AN=537850495
-- 11/17/1999 hobbs
welch Closed ticket [218278ffff].
[History diff]2000-10-26 08:18:57
Log in (anonymous is fine) to add a comment.