From cc7e4837691316c9edf52aea1e1cc585ac69dda3 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 18 Sep 2024 10:53:49 +0000 Subject: amend to [02d5d65d70]: fixed memory leak (using translated path) --- generic/tclZipfs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index 84e4d34..6741d4b 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -5857,6 +5857,7 @@ ZipFSPathInFilesystemProc( { Tcl_Size len; char *path; + int ret, decrRef = 0; if (TclFSCwdIsNative() || Tcl_FSGetPathType(pathPtr) == TCL_PATH_ABSOLUTE) { /* @@ -5869,6 +5870,7 @@ ZipFSPathInFilesystemProc( if (pathPtr == NULL) { return -1; } + decrRef = 1; /* Tcl_FSGetTranslatedPath increases refCount */ } else { /* * Make sure the normalized path is set. @@ -5878,6 +5880,7 @@ ZipFSPathInFilesystemProc( if (!pathPtr) { return -1; } + /* Tcl_FSGetNormalizedPath doesn't increase refCount */ } path = TclGetStringFromObj(pathPtr, &len); @@ -5886,10 +5889,15 @@ ZipFSPathInFilesystemProc( * and sufficient condition as zipfs mounts at arbitrary paths are * not permitted (unlike Androwish). */ - return ( + ret = ( (len < ZIPFS_VOLUME_LEN) || strncmp(path, ZIPFS_VOLUME, ZIPFS_VOLUME_LEN) ) ? -1 : TCL_OK; + + if (decrRef) { + Tcl_DecrRefCount(pathPtr); + } + return ret; } /* -- cgit v0.12