summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-10-21 06:09:14 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-10-21 06:09:14 (GMT)
commit5dea841618be90edfbda3b46384c3860914864c0 (patch)
treef50871e0010ac8f7d669e169e23442e249fb10bd
parent6eac416e1dac9fc63b8ad41757cc3b4cf1965b82 (diff)
parentffb1230a3c6dfdbb1ba974b44ce60839cc066ddb (diff)
downloadtcl-5dea841618be90edfbda3b46384c3860914864c0.zip
tcl-5dea841618be90edfbda3b46384c3860914864c0.tar.gz
tcl-5dea841618be90edfbda3b46384c3860914864c0.tar.bz2
Merge 8.7 - Bug [33b2486199] - thread create/release unmounts zipfs
-rw-r--r--generic/tclIO.c1
-rw-r--r--generic/tclIOUtil.c1
-rw-r--r--generic/tclZipfs.c55
-rw-r--r--libtommath/bn_mp_div.c4
-rw-r--r--tests/zipfs.test9
-rw-r--r--win/nmakehlp.c5
6 files changed, 42 insertions, 33 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 16bb69b..9f1c363 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -698,7 +698,6 @@ TclFinalizeIOSubsystem(void)
FreeBinaryEncoding();
TclpFinalizeSockets();
TclpFinalizePipes();
- TclZipfsFinalize();
}
/*
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index d480d2e..921d79e 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -761,6 +761,7 @@ TclFinalizeFilesystem(void)
* needed.
*/
+ TclZipfsFinalize();
fsRecPtr = filesystemList;
while (fsRecPtr != NULL) {
FilesystemRecord *tmpFsRecPtr = fsRecPtr->nextPtr;
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c
index 42d36c4..9d3a3be 100644
--- a/generic/tclZipfs.c
+++ b/generic/tclZipfs.c
@@ -6259,15 +6259,25 @@ ZipfsAppHookFindTclInit(
}
#endif
+/*
+ *------------------------------------------------------------------------
+ *
+ * TclZipfsFinalize --
+ *
+ * Frees all zipfs resources IRRESPECTIVE of open channels (there should
+ * not be any!) etc. To be called at process exit time (from
+ * Tcl_Finalize->TclFinalizeFilesystem)
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Frees up archives loaded into memory.
+ *
+ *------------------------------------------------------------------------
+ */
void TclZipfsFinalize(void)
{
- /*
- * Finalization steps:
- * For every mounted archive, if it no longer has any open handles
- * clean up the mount and associated zip file entries.
- * If there are no more mounted archives, clean up and free the
- * ZipFS.fileHash and ZipFS.zipHash tables.
- */
WriteLock();
if (!ZipFS.initialized) {
Unlock();
@@ -6279,30 +6289,21 @@ void TclZipfsFinalize(void)
for (hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &zipSearch); hPtr;
hPtr = Tcl_NextHashEntry(&zipSearch)) {
ZipFile *zf = (ZipFile *) Tcl_GetHashValue(hPtr);
- if (zf->numOpen == 0) {
- Tcl_DeleteHashEntry(hPtr);
- CleanupMount(zf);
- ZipFSCloseArchive(NULL, zf);
- Tcl_Free(zf);
- }
+ Tcl_DeleteHashEntry(hPtr);
+ CleanupMount(zf); /* Frees file entries belonging to the archive */
+ ZipFSCloseArchive(NULL, zf);
+ Tcl_Free(zf);
}
- hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &zipSearch);
- if (hPtr == NULL) {
- hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &zipSearch);
- if (hPtr == NULL) {
- /* Both hash tables empty. Free all resources */
- Tcl_FSUnregister(&zipfsFilesystem);
- Tcl_DeleteHashTable(&ZipFS.fileHash);
- Tcl_DeleteHashTable(&ZipFS.zipHash);
- if (ZipFS.fallbackEntryEncoding) {
- Tcl_Free(ZipFS.fallbackEntryEncoding);
- ZipFS.fallbackEntryEncoding = NULL;
- }
- ZipFS.initialized = 0;
- }
+ Tcl_FSUnregister(&zipfsFilesystem);
+ Tcl_DeleteHashTable(&ZipFS.fileHash);
+ Tcl_DeleteHashTable(&ZipFS.zipHash);
+ if (ZipFS.fallbackEntryEncoding) {
+ Tcl_Free(ZipFS.fallbackEntryEncoding);
+ ZipFS.fallbackEntryEncoding = NULL;
}
+ ZipFS.initialized = 0;
Unlock();
}
diff --git a/libtommath/bn_mp_div.c b/libtommath/bn_mp_div.c
index 71de55b..bca227d 100644
--- a/libtommath/bn_mp_div.c
+++ b/libtommath/bn_mp_div.c
@@ -31,7 +31,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
}
/* init our temps */
- if ((err = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) {
+ if ((err = mp_init_multi(&ta, &tb, &tq, &q, (void *)NULL)) != MP_OKAY) {
return err;
}
@@ -64,7 +64,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : n;
}
LBL_ERR:
- mp_clear_multi(&ta, &tb, &tq, &q, NULL);
+ mp_clear_multi(&ta, &tb, &tq, &q, (void *)NULL);
return err;
}
diff --git a/tests/zipfs.test b/tests/zipfs.test
index b8880b5..d77369b 100644
--- a/tests/zipfs.test
+++ b/tests/zipfs.test
@@ -19,6 +19,7 @@ if {"::tcltest" ni [namespace children]} {
source [file join [file dirname [info script]] tcltests.tcl]
testConstraint zipfs [expr {[llength [info commands zipfs]]}]
+testConstraint thread [expr {0 == [catch {package require Thread 2.8-}]}]
set ziproot [zipfs root]
@@ -1923,6 +1924,14 @@ namespace eval test_ns_zipfs {
zipfs unmount $mt
} -result ""
+ test bug-33b2486199 "zipfs unmounted on thread exit" -constraints {
+ thread
+ } -body {
+ set before [lsort [zipfs mount]]
+ thread::release [thread::create]
+ after 100; # Needed to allow the spawned thread to exit to trigger bug
+ string equal $before [lsort [zipfs mount]]
+ } -result 1
}
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index c8b39a7..b0799f8 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -19,7 +19,6 @@
#pragma comment (lib, "kernel32.lib")
#endif
#include <stdio.h>
-#include <math.h>
/*
* This library is required for x64 builds with _some_ versions of MSVC
@@ -272,7 +271,7 @@ CheckForCompilerFeature(
if (!ok) {
DWORD err = GetLastError();
int chars = snprintf(msg, sizeof(msg) - 1,
- "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
@@ -406,7 +405,7 @@ CheckForLinkerFeature(
if (!ok) {
DWORD err = GetLastError();
int chars = snprintf(msg, sizeof(msg) - 1,
- "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ "Tried to launch: \"%s\", but got error [%lu]: ", cmdline, err);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],