Skip to content
Tcl Source Code History Of Ticket 756791ffffffffffffffffffffffffffffffffff
Login

History Of Ticket 756791ffffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 756791ffffffffffffffffffffffffffffffffff

  1. Ticket change [cf6467decc] (rid 112970) by landonf on 2003-06-18 19:17:52:

    1. assignee initialized to: "hobbs"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Tcl incorrectly uses ckfree() on pointers supplied with a 
      freeProc of free()
      
      Fix attached, explanation below.
      
      Prototype for Tcl_SetResult:
      Tcl_SetResult(interp, string, freeProc)
      
      Tcl_SetResult allows one to specify any custom free function 
      that matches the Tcl_FreeProc prototype, or one of 
      TCL_VOLATILE, TCL_STATIC, or TCL_DYNAMIC.
      
      If one specifies TCL_DYNAMIC, it is assumed that the string 
      pointer is owned by the Tcl allocator, and ckfree() is used to 
      free the allocated memory.
      
      However, if free() is specified, ckfree() is ALSO used to free 
      the allocated memory. This is incorrect, as ckfree() can not 
      be used on memory allocated by malloc.
      
              if ((iPtr->freeProc == TCL_DYNAMIC)
                      || (iPtr->freeProc == (Tcl_FreeProc *) 
      free)) {
      ckfree(iPtr->result);
      }
      
      When looking through the code, I found that this error was 
      propagated in numerous other locations. Attached is a fix. In 
      all cases, the above if conditional has been changed to 
      remove the test for iPtr->freeProc == (Tcl_FreeProc *) 
      free. In example:
      if (iPtr->freeProc == TCL_DYNAMIC) {
      ...
      }
      
      Detailed problem information follows:
      
      Tcl_DStringGetResult(interp, dsPtr):
      If iPtr->freeProc is either TCL_DYNAMIC or free, dsPtr-
      >string is set to iPtr->result. Later, when Tcl_DStringFree() 
      is called, ckfree() will be called on dsPtr->string.
      
      Tcl_Release(clientData):
      If Tcl_EventuallyFree has been called on the pointer passed 
      to Tcl_Release, refPtr->mustFree will be set, and refPtr-
      >freeProc will be set to the free function given to 
      Tcl_EventuallyFree. If refPtr->freeProc is either 
      TCL_DYNAMIC or free, ckfree(clientData) will be called.
      
      Tcl_EventuallyFree(clientData, freeProc):
      If there is no reference in the refArray for the clientData 
      pointer, clientData is immediately freed using the supplied 
      freeProc, unless freeProc == free() or TCL_DYNAMIC, and 
      then, ckfree(clientData) is called.
      
      Tcl_DiscardResult(statePtr)
      If Tcl_SetResult was called with a freeProc of free, 
      Tcl_SaveResult(interp, statePtr) will set statePtr->freeProc 
      to iPtr->freeProc, and statePtr->result to iPtr->result. When 
      Tcl_DiscardResult is called on this statePtr, if statePtr-
      >freeProc is TCL_DYNAMIC or free(), ckfree() is called on 
      statPtr->result.
      
      Tcl_SetResult(interp, string, freeProc)
      If the old interp->freeProc is TCL_DYNAMIC or free(), ckfree 
      is called.
      
      Tcl_SetObjResult(interp, objPtr)
      If interp->result && interp->freeProc are not NULL, and 
      interp->freeProc is either TCL_DYNAMIC or free(), ckfree() 
      is called.
      
      Tcl_GetObjResult(interp):
      If interp->result && interp->freeProc are not NULL, and 
      interp->freeProc is either TCL_DYNAMIC or free(), ckfree() 
      is called.
      
      Tcl_FreeResult(interp):
      If interp->freeProc is not NULL, and interp->freeProc is 
      either TCL_DYNAMIC or free(), ckfree() is called.
      
      
    4. foundin initialized to: "None"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "landonf"
    9. subsystem initialized to: "41. Memory Allocation"
    10. title initialized to:
      Tcl incorrectly uses ckfree() when freeProc == free()
      
    11. type initialized to: "Bug"
  2. Add attachment "tcl-diff-ckfree.diff" [807ab7fd71] (rid 116878) by landonf on 2003-06-19 02:17:52.

  3. Ticket change [4eb2e33d18] (rid 125688) by landonf on 2003-06-19 02:17:52:

    1. icomment:
      
      
      File Added - 53476: tcl-diff-ckfree.diff
      
      
      
    2. login: "landonf"
    3. mimetype: "text/plain"
    4. username: "landonf"
  4. Ticket change [bc08351222] (rid 129589) by landonf on 2003-06-19 06:44:13:

    1. priority changed to: "7 High"
    2. title changed to:
      [patch]Tcl incorrectly uses ckfree() when freeProc == free()
      
  5. Ticket change [ad195df1e2] (rid 101415) by landonf on 2003-07-16 06:58:21:

    1. priority changed to: "9 Immediate"
  6. Ticket change [449af607a2] (rid 116735) by hobbs on 2003-07-17 04:25:32:

    1. closedate changed to: "2003-07-16T21:25:32"
    2. closer changed to: "hobbs"
    3. icomment:
      Logged In: YES 
      user_id=72656
      
      patch had one bug.  commited fixed for 8.5a and 8.4.4.
      
      
    4. login: "hobbs"
    5. mimetype: "text/plain"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "hobbs"
  7. Ticket change [d85b07e2ac] (rid 219314) by chrstphrchvz on 2023-10-11 12:58:56:

    1. assignee changed to: "aku"
    2. closedate changed to: "2460229.04093311"
    3. closer changed to: "chrstphrchvz"
    4. comment changed to:
      Tcl incorrectly uses ckfree() on pointers supplied with a 
      freeProc of free()
      
      Fix attached, explanation below.
      
      Prototype for Tcl_SetResult:
      Tcl_SetResult(interp, string, freeProc)
      
      Tcl_SetResult allows one to specify any custom free function 
      that matches the Tcl_FreeProc prototype, or one of 
      TCL_VOLATILE, TCL_STATIC, or TCL_DYNAMIC.
      
      If one specifies TCL_DYNAMIC, it is assumed that the string 
      pointer is owned by the Tcl allocator, and ckfree() is used to 
      free the allocated memory.
      
      However, if free() is specified, ckfree() is ALSO used to free 
      the allocated memory. This is incorrect, as ckfree() can not 
      be used on memory allocated by malloc.
      
              if ((iPtr->freeProc == TCL_DYNAMIC)
                      || (iPtr->freeProc == (Tcl_FreeProc *) 
      free)) {
      ckfree(iPtr->result);
      }
      
      When looking through the code, I found that this error was 
      propagated in numerous other locations. Attached is a fix. In 
      all cases, the above if conditional has been changed to 
      remove the test for iPtr->freeProc == (Tcl_FreeProc *) 
      free. In example:
      if (iPtr->freeProc == TCL_DYNAMIC) {
      ...
      }
      
      Detailed problem information follows:
      
      Tcl_DStringGetResult(interp, dsPtr):
      If iPtr->freeProc is either TCL_DYNAMIC or free, dsPtr-
      >string is set to iPtr->result. Later, when Tcl_DStringFree() 
      is called, ckfree() will be called on dsPtr->string.
      
      Tcl_Release(clientData):
      If Tcl_EventuallyFree has been called on the pointer passed 
      to Tcl_Release, refPtr->mustFree will be set, and refPtr-
      >freeProc will be set to the free function given to 
      Tcl_EventuallyFree. If refPtr->freeProc is either 
      TCL_DYNAMIC or free, ckfree(clientData) will be called.
      
      Tcl_EventuallyFree(clientData, freeProc):
      If there is no reference in the refArray for the clientData 
      pointer, clientData is immediately freed using the supplied 
      freeProc, unless freeProc == free() or TCL_DYNAMIC, and 
      then, ckfree(clientData) is called.
      
      Tcl_DiscardResult(statePtr)
      If Tcl_SetResult was called with a freeProc of free, 
      Tcl_SaveResult(interp, statePtr) will set statePtr->freeProc 
      to iPtr->freeProc, and statePtr->result to iPtr->result. When 
      Tcl_DiscardResult is called on this statePtr, if statePtr-
      >freeProc is TCL_DYNAMIC or free(), ckfree() is called on 
      statPtr->result.
      
      Tcl_SetResult(interp, string, freeProc)
      If the old interp->freeProc is TCL_DYNAMIC or free(), ckfree 
      is called.
      
      Tcl_SetObjResult(interp, objPtr)
      If interp->result && interp->freeProc are not NULL, and 
      interp->freeProc is either TCL_DYNAMIC or free(), ckfree() 
      is called.
      
      Tcl_GetObjResult(interp):
      If interp->result && interp->freeProc are not NULL, and 
      interp->freeProc is either TCL_DYNAMIC or free(), ckfree() 
      is called.
      
      Tcl_FreeResult(interp):
      If interp->freeProc is not NULL, and interp->freeProc is 
      either TCL_DYNAMIC or free(), ckfree() is called.
      
    5. icomment:
      There is still an instance of this issue in Tk: [https://core.tcl-lang.org/tk/info/9675dd5916ba]
      
    6. login: "chrstphrchvz"
    7. mimetype: "text/x-fossil-wiki"
    8. severity changed to: "Minor"