diff options
author | dgp <dgp@noemail.net> | 2017-07-06 15:46:58 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2017-07-06 15:46:58 (GMT) |
commit | 75b64891bb0b22ed2fa6193d32299eee8ef90776 (patch) | |
tree | 64ce052dbb9466b7d23aede20e8c0378681c4916 | |
parent | cfca4dc7b38754a92a8833e4c7b0eec818596e03 (diff) | |
download | tcl-75b64891bb0b22ed2fa6193d32299eee8ef90776.zip tcl-75b64891bb0b22ed2fa6193d32299eee8ef90776.tar.gz tcl-75b64891bb0b22ed2fa6193d32299eee8ef90776.tar.bz2 |
Alternative fix for memleaks in fs path join machinery.
FossilOrigin-Name: 6ab9649e669f1423c7411892a601580ee38e10c9
-rw-r--r-- | generic/tclPathObj.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c index 31ed68e..f8015b2 100644 --- a/generic/tclPathObj.c +++ b/generic/tclPathObj.c @@ -13,6 +13,7 @@ #include "tclInt.h" #include "tclFileSystem.h" +#include <assert.h> /* * Prototypes for functions defined later in this file. @@ -849,11 +850,17 @@ TclJoinPath( int elements, Tcl_Obj * const objv[]) { - Tcl_Obj *res; + Tcl_Obj *res = NULL; int i; const Tcl_Filesystem *fsPtr = NULL; - res = NULL; + assert ( elements >= 0 ); + + if (elements == 0) { + return Tcl_NewObj(); + } + + assert ( elements > 0 ); for (i = 0; i < elements; i++) { int driveNameLength, strEltLen, length; @@ -893,9 +900,7 @@ TclJoinPath( * the base itself is just fine! */ - if (res != NULL) { - TclDecrRefCount(res); - } + assert ( res == NULL ); return elt; } @@ -918,9 +923,8 @@ TclJoinPath( if ((tclPlatform != TCL_PLATFORM_WINDOWS) || (strchr(Tcl_GetString(elt), '\\') == NULL)) { - if (res != NULL) { - TclDecrRefCount(res); - } + + assert ( res == NULL ); if (PATHFLAGS(elt)) { return TclNewFSPathObj(elt, str, len); @@ -940,18 +944,14 @@ TclJoinPath( * more general code below handle things. */ } else if (tclPlatform == TCL_PLATFORM_UNIX) { - if (res != NULL) { - TclDecrRefCount(res); - } + assert ( res == NULL ); return tailObj; } else { const char *str = TclGetString(tailObj); if (tclPlatform == TCL_PLATFORM_WINDOWS) { if (strchr(str, '\\') == NULL) { - if (res != NULL) { - TclDecrRefCount(res); - } + assert ( res == NULL ); return tailObj; } } @@ -1087,6 +1087,7 @@ TclJoinPath( if (sep != NULL) { separator = TclGetString(sep)[0]; + Tcl_DecrRefCount(sep); } /* Safety check in case the VFS driver caused sharing */ if (Tcl_IsShared(res)) { @@ -1122,9 +1123,7 @@ TclJoinPath( Tcl_SetObjLength(res, length); } } - if (res == NULL) { - res = Tcl_NewObj(); - } + assert ( res != NULL ); return res; } |