summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-07-06 15:46:58 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-07-06 15:46:58 (GMT)
commit8f25f4915310d084a6d0e973b8aa85ba18d7bee7 (patch)
tree5cbe0c7abb4f1e07cce0a9c1a4c388889d19fc3a /generic
parent41de3a7f8d82c4026e4586675ca4e24a585627b7 (diff)
downloadtcl-8f25f4915310d084a6d0e973b8aa85ba18d7bee7.zip
tcl-8f25f4915310d084a6d0e973b8aa85ba18d7bee7.tar.gz
tcl-8f25f4915310d084a6d0e973b8aa85ba18d7bee7.tar.bz2
Alternative fix for memleaks in fs path join machinery.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclPathObj.c33
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;
}