Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e09d42bf22511ae24bccbfd94d0195d0cf8119b9
Ticket: adb198c256df8c4192838cc3c1112fb2821314e9
Potential Tcl_Obj leak in tclPathObj.c
User & Date: chw on 2017-07-02 05:03:00
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    I think there are two potential Tcl_Obj leaks in the current version
    of tclPathObj.c in the TclJoinPath function, as shown in the following
    patch.
    
    The first in a newly introduced code path which releases a Tcl_Obj
    although it gets used later, the second regarding the path name
    separator returned as an optional new Tcl_Obj from a VFS implementation
    which never gets released.
    
    Index: generic/tclPathObj.c
    ==================================================================
    --- generic/tclPathObj.c
    +++ generic/tclPathObj.c
    @@ -916,22 +916,27 @@
     		     * cannot have backslashes either.
     		     */
     
     		    if ((tclPlatform != TCL_PLATFORM_WINDOWS)
     			    || (strchr(Tcl_GetString(elt), '\\') == NULL)) {
    -			if (res != NULL) {
    -			    TclDecrRefCount(res);
    -			}
    -
     			if (PATHFLAGS(elt)) {
    +			    if (res != NULL) {
    +				TclDecrRefCount(res);
    +			    }
     			    return TclNewFSPathObj(elt, str, len);
     			}
     			if (TCL_PATH_ABSOLUTE != Tcl_FSGetPathType(elt)) {
    +			    if (res != NULL) {
    +				TclDecrRefCount(res);
    +			    }
     			    return TclNewFSPathObj(elt, str, len);
     			}
     			(void) Tcl_FSGetNormalizedPath(NULL, elt);
     			if (elt == PATHOBJ(elt)->normPathPtr) {
    +			    if (res != NULL) {
    +				TclDecrRefCount(res);
    +			    }
     			    return TclNewFSPathObj(elt, str, len);
     			}
     		    }
     		}
     
    @@ -1085,10 +1090,11 @@
     	    if (fsPtr->filesystemSeparatorProc != NULL) {
     		Tcl_Obj *sep = fsPtr->filesystemSeparatorProc(res);
     
     		if (sep != NULL) {
     		    separator = TclGetString(sep)[0];
    +		    Tcl_DecrRefCount(sep);
     		}
     		/* Safety check in case the VFS driver caused sharing */
     		if (Tcl_IsShared(res)) {
     		    TclDecrRefCount(res);
     		    res = Tcl_DuplicateObj(res);
    
    ==================================================================
    
  5. foundin changed to: "current"
  6. is_private changed to: "0"
  7. login: "chw"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "0b3aff16612e1e9f3b675963fa64e01bd1d89307"
  10. resolution changed to: "None"
  11. severity changed to: "Critical"
  12. status changed to: "Open"
  13. submitter changed to: "chw"
  14. subsystem changed to: "36. Pathname Management"
  15. title changed to: "Potential Tcl_Obj leak in tclPathObj.c"
  16. type changed to: "Bug"