diff options
author | sebres <sebres@users.sourceforge.net> | 2015-07-30 18:22:27 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2015-07-30 18:22:27 (GMT) |
commit | e52a9a2b2f4cab99c68114c437d7a45685a07210 (patch) | |
tree | ce9772a73c81d6e381188ac11b6a0c9861b14d9a /win | |
parent | 27c8daeb604edffdf3a5229bf7c5f4f3aec99793 (diff) | |
download | tcl-e52a9a2b2f4cab99c68114c437d7a45685a07210.zip tcl-e52a9a2b2f4cab99c68114c437d7a45685a07210.tar.gz tcl-e52a9a2b2f4cab99c68114c437d7a45685a07210.tar.bz2 |
Fix bug [f00009f7ce]: memory (object) leaks in TclNativeCreateNativeRep for windows platform:
missing decrement of refCount, because of confusing differently behavior Tcl_FSGetTranslatedPath vs Tcl_FSGetNormalizedPath.
Diffstat (limited to 'win')
-rwxr-xr-x | win/tclWinFile.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 5ee73d5..6b9d373 100755 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -2897,7 +2897,7 @@ ClientData TclNativeCreateNativeRep( Tcl_Obj *pathPtr) { - WCHAR *nativePathPtr; + WCHAR *nativePathPtr = NULL; const char *str; Tcl_Obj *validPathPtr; size_t len; @@ -2911,15 +2911,21 @@ TclNativeCreateNativeRep( */ validPathPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr); + if (validPathPtr == NULL) { + return NULL; + } + /* refCount of validPathPtr was already incremented in Tcl_FSGetTranslatedPath */ } else { /* * Make sure the normalized path is set. */ validPathPtr = Tcl_FSGetNormalizedPath(NULL, pathPtr); - } - if (validPathPtr == NULL) { - return NULL; + if (validPathPtr == NULL) { + return NULL; + } + /* validPathPtr returned from Tcl_FSGetNormalizedPath is owned by Tcl, so incr refCount here */ + Tcl_IncrRefCount(validPathPtr); } str = Tcl_GetString(validPathPtr); @@ -2927,7 +2933,7 @@ TclNativeCreateNativeRep( if (strlen(str)!=(unsigned int)len) { /* String contains NUL-bytes. This is invalid. */ - return 0; + goto done; } /* For a reserved device, strip a possible postfix ':' */ len = WinIsReserved(str); @@ -2936,13 +2942,13 @@ TclNativeCreateNativeRep( * 0xC0 0x80 (== overlong NUL). See bug [3118489]: NUL in filenames */ len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, 0, 0); if (len==0) { - return 0; + goto done; } } /* Overallocate 6 chars, making some room for extended paths */ wp = nativePathPtr = ckalloc( (len+6) * sizeof(WCHAR) ); if (nativePathPtr==0) { - return 0; + goto done; } MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str, -1, nativePathPtr, len+1); /* @@ -2993,6 +2999,10 @@ TclNativeCreateNativeRep( } ++wp; } + + done: + + TclDecrRefCount(validPathPtr); return nativePathPtr; } |