Tcl Source Code

View Ticket
Login
Ticket UUID: 2577420
Title: Tcl_GetInterpPath produces invalid path.
Type: Bug Created on: 2009-02-07 14:54:54
Submitter: sbron Assigned to: hobbs
Subsystem: 20. [interp] Severity:
Priority: 5 Medium Last modified: 2026-10-17 08:39:47
Status: Open Closed by:
Resolution: None Closed on:
Version: 9.0.5, 9.1.0
Description:
Tcl_GetInterpPath returns TCL_OK when called form within a Tcl_InterpDeleteProc that runs when the slave interp is deleted, but the path it produces is garbage.

The following code prints some strange character when it is registered with Tcl_CallWhenDeleted for some slave interpreter and that interpreter is subsequently deleted.

void InterpDelete(ClientData dummy, Tcl_Interp *interp)
{
   Tcl_Interp *master;
   master = Tcl_GetMaster(interp);
   if (master != NULL) {
      Tcl_GetInterpPath(master, interp);
      printf("Path: %s\n", Tcl_GetStringResult(master));
   }
}

Either the function should produce the correct path, or it should return TCL_ERROR. In the latter case it would also be helpful if the manual page would mention that this function cannot be used when the interp is in the process of being deleted.

Problem was found on SuSE linux 11.0.
User Comments:
mistachkin added on 2009-03-17 15:01:54:
This bug may be related to 1502071.

mistachkin added on 2009-03-17 15:06:52:
This bug may be related to 1502071.

serhiy.storchaka added on 2026-10-17 08:39:47:

Still a use-after-free in 9.0 and 9.1 (ASan): the child's entry in the parent's child table is removed before the child's Tcl_CallWhenDeleted() callbacks run, and the InterpInfo may be freed before them too, because it is freed by another delete callback. 8.6 and 9.0 print the right path only because the freed memory still holds it. Proposed fix in branch interp-delete-callbacks-path: unlink after Tcl_DeleteInterp(), and free the InterpInfo after all delete callbacks. No test, since no script command can register such a callback.