summaryrefslogtreecommitdiffstats
path: root/generic/tclZipfs.c
diff options
context:
space:
mode:
authorpooryorick <com.digitalsmarties@pooryorick.com>2021-05-13 12:49:23 (GMT)
committerpooryorick <com.digitalsmarties@pooryorick.com>2021-05-13 12:49:23 (GMT)
commit30dbe727465cd78003b4ff988bebecb846fc9e89 (patch)
treeb948f54fb8748eb7ce7306bb1a83266bfa01e5a8 /generic/tclZipfs.c
parent39886e8c000aa39f38fb426136f09efe384b67c3 (diff)
downloadtcl-30dbe727465cd78003b4ff988bebecb846fc9e89.zip
tcl-30dbe727465cd78003b4ff988bebecb846fc9e89.tar.gz
tcl-30dbe727465cd78003b4ff988bebecb846fc9e89.tar.bz2
Fix remaining leaks in Zipfs finalization.
Diffstat (limited to 'generic/tclZipfs.c')
-rw-r--r--generic/tclZipfs.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c
index 16eac74..bad4cb9 100644
--- a/generic/tclZipfs.c
+++ b/generic/tclZipfs.c
@@ -249,7 +249,7 @@ typedef struct ZipChannel {
* Most are kept in single ZipFS struct. When build with threading support
* this struct is protected by the ZipFSMutex (see below).
*
- * The "fileHash" component is the process wide global table of all known ZIP
+ * The "fileHash" component is the process-wide global table of all known ZIP
* archive members in all mounted ZIP archives.
*
* The "zipHash" components is the process wide global table of all mounted
@@ -348,6 +348,7 @@ static int ZipMapArchive(Tcl_Interp *interp, ZipFile *zf,
static void ZipfsExitHandler(ClientData clientData);
static void ZipfsMountExitHandler(ClientData clientData);
static void ZipfsSetup(void);
+static void ZipfsFinalize(void);
static int ZipChannelClose(void *instanceData,
Tcl_Interp *interp, int flags);
static Tcl_DriverGetHandleProc ZipChannelGetFile;
@@ -5734,21 +5735,45 @@ static void
ZipfsExitHandler(
ClientData clientData)
{
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch search;
+ if (ZipFS.initialized != -1) {
+ hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &search);
+ if (hPtr == NULL) {
+ ZipfsFinalize();
+ } else {
+ /* ZipFS.fallbackEntryEncoding was already freed by
+ * ZipfsMountExitHandler
+ */
+ }
+ }
+}
+
+static void
+ZipfsFinalize(void) {
+ Tcl_DeleteHashTable(&ZipFS.fileHash);
ckfree(ZipFS.fallbackEntryEncoding);
+ ZipFS.initialized = -1;
}
-
static void
ZipfsMountExitHandler(
ClientData clientData)
{
+ Tcl_HashEntry *hPtr;
+ Tcl_HashSearch search;
+
ZipFile *zf = (ZipFile *) clientData;
if (TCL_OK != TclZipfs_Unmount(NULL, zf->mountPoint)) {
Tcl_Panic("tried to unmount busy filesystem");
}
- ckfree(ZipFS.fallbackEntryEncoding);
+ hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &search);
+ if (hPtr == NULL) {
+ ZipfsFinalize();
+ }
+
}
/*