Artifacts Associated With Ticket adb198c256
Ticket change [e09d42bf22] (rid 154856) by chw on 2017-07-02 05:03:00:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized 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); ================================================================== - foundin initialized to: "current"
- is_private initialized to: "0"
- login: "chw"
- priority initialized to: "5 Medium"
- private_contact initialized to: "0b3aff16612e1e9f3b675963fa64e01bd1d89307"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "chw"
- subsystem initialized to: "36. Pathname Management"
- title initialized to: "Potential Tcl_Obj leak in tclPathObj.c"
- type initialized to: "Bug"
Ticket change [b87c161f29] (rid 154871) by sebres on 2017-07-03 09:25:46:
- closedate changed to: "2457937.89289918"
- closer changed to: "sebres"
- icomment:
Fixed for 8.6 and 8.5. Thanks.
- login: "sebres"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [5ea92d6766] (rid 155099) by dgp on 2017-07-06 12:35:09:
- closedate changed to: "2457941.02442013"
- closer changed to: "dgp"
- icomment:
Any test cases?
- login: "dgp"
- mimetype: "text/plain"
Ticket change [5572923f2f] (rid 155100) by dgp on 2017-07-06 14:08:26:
- closedate changed to: "2457941.08919503"
- icomment:
Still looking, but it appears this is tidying up some code that cannot actually ever be reached. I think we'd be better eliminating it.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [d36648d494] (rid 155101) by dgp on 2017-07-06 14:14:56:
- closedate changed to: "2457941.09370936"
- icomment:
This large conditional block https://core.tcl.tk/tcl/artifact/6c6428a1c565405c?ln=877-960 is conditioned on (i == 0) among others. That means we can only execute this block on the first iteration of the for loop, and at that point, nothing has had the chance to make res contain anything other than NULL. Much code directing what to do when (res != NULL) is actually useless. Some asserts would be better, I think.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [463995cb42] (rid 155102) by sebres on 2017-07-06 14:56:39:
- closedate changed to: "2457941.1226824"
- closer changed to: "sebres"
- icomment:
> That means we can only execute this block on the first iteration of the for loop Hmm, strange... The question is "Why this belong then to the cycle, and not above it?" I fixed it just by the way like "minimalistic" surgery, so don't observed the cycle conditions.
- login: "sebres"
- mimetype: "text/plain"
Ticket change [d0d9044cd8] (rid 155103) by dgp on 2017-07-06 15:25:36:
- closedate changed to: "2457941.14278435"
- closer changed to: "dgp"
- icomment:
I think that would be a further improvement. Will look into it. The code is messy, fragile, and abandoned by the originator, so it improves only in tiny, tentative incremental changes, usually motivated by actual bugs and crashes, not just aesthetic concerns. Someone who really got up a head of steam to make it much much better would be better off rewriting the thing from the ground up, IMO. That said, the memleak in the separator handling from a VFS looks legit and properly fixed.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [1e4e82b495] (rid 155104) by dgp on 2017-07-06 15:28:37:
- closedate changed to: "2457941.14488277"
- icomment:
Having said that, it's worth noting that the codebases of the 8.5 and 8.6 filesystem implementations have diverged, and I lack much confidence that a patch developed for one can lightly be applied to the other. I'd be happier leaving 8.5 untouched, and if that leaves unfixed bugs, then the fix for them is to start using 8.6.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [ae6e357407] (rid 155111) by dgp on 2017-07-06 16:35:32:
- closedate changed to: "2457941.19134904"
- icomment:
Revised the fix on the 8.6 branch; will merge fwd.
- login: "dgp"
- mimetype: "text/plain"