summaryrefslogtreecommitdiffstats
path: root/generic/tclZipfs.c
diff options
context:
space:
mode:
authorpooryorick <com.digitalsmarties@pooryorick.com>2021-04-20 19:33:57 (GMT)
committerpooryorick <com.digitalsmarties@pooryorick.com>2021-04-20 19:33:57 (GMT)
commitbc8789e84006d564fd479cfbd2e05c9775c7abf0 (patch)
tree0098c1a23ab7e9edf7e0220a464deec48944c3f9 /generic/tclZipfs.c
parent14ead72e1ac39741ca435ee5635738ca1285a61b (diff)
downloadtcl-bc8789e84006d564fd479cfbd2e05c9775c7abf0.zip
tcl-bc8789e84006d564fd479cfbd2e05c9775c7abf0.tar.gz
tcl-bc8789e84006d564fd479cfbd2e05c9775c7abf0.tar.bz2
Fix for [1f4af0a127369d4a1], tclZipfs storage cleanup issue.
Diffstat (limited to 'generic/tclZipfs.c')
-rw-r--r--generic/tclZipfs.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c
index 3083f1d..8706d5a 100644
--- a/generic/tclZipfs.c
+++ b/generic/tclZipfs.c
@@ -1540,7 +1540,7 @@ IsPasswordValid(
static int
ZipFSCatalogFilesystem(
Tcl_Interp *interp, /* Current interpreter. NULLable. */
- ZipFile *zf0, /* Temporary buffer hold archive descriptors */
+ ZipFile *zf, /* Temporary buffer hold archive descriptors */
const char *mountPoint, /* Mount point path. */
const char *passwd, /* Password for opening the ZIP, or NULL if
* the ZIP is unprotected. */
@@ -1548,7 +1548,7 @@ ZipFSCatalogFilesystem(
{
int pwlen, isNew;
size_t i;
- ZipFile *zf;
+ ZipFile *zf0;
ZipEntry *z;
Tcl_HashEntry *hPtr;
Tcl_DString ds, dsm, fpBuf;
@@ -1570,10 +1570,12 @@ ZipFSCatalogFilesystem(
* Validate the TOC data. If that's bad, things fall apart.
*/
- if (zf0->baseOffset >= zf0->length || zf0->passOffset >= zf0->length ||
- zf0->directoryOffset >= zf0->length) {
+ if (zf->baseOffset >= zf->length || zf->passOffset >= zf->length ||
+ zf->directoryOffset >= zf->length) {
ZIPFS_ERROR(interp, "bad zip data");
ZIPFS_ERROR_CODE(interp, "BAD_ZIP");
+ ZipFSCloseArchive(interp, zf);
+ ckfree(zf);
return TCL_ERROR;
}
@@ -1594,19 +1596,14 @@ ZipFSCatalogFilesystem(
hPtr = Tcl_CreateHashEntry(&ZipFS.zipHash, mountPoint, &isNew);
if (!isNew) {
if (interp) {
- zf = (ZipFile *) Tcl_GetHashValue(hPtr);
+ zf0 = (ZipFile *) Tcl_GetHashValue(hPtr);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "%s is already mounted on %s", zf->name, mountPoint));
+ "%s is already mounted on %s", zf0->name, mountPoint));
ZIPFS_ERROR_CODE(interp, "MOUNTED");
}
Unlock();
- ZipFSCloseArchive(interp, zf0);
- return TCL_ERROR;
- }
- zf = AllocateZipFile(interp, strlen(mountPoint));
- if (!zf) {
- Unlock();
- ZipFSCloseArchive(interp, zf0);
+ ZipFSCloseArchive(interp, zf);
+ ckfree(zf);
return TCL_ERROR;
}
Unlock();
@@ -1615,7 +1612,6 @@ ZipFSCatalogFilesystem(
* Convert to a real archive descriptor.
*/
- *zf = *zf0;
zf->mountPoint = (char *) Tcl_GetHashKey(&ZipFS.zipHash, hPtr);
Tcl_CreateExitHandler(ZipfsExitHandler, zf);
zf->mountPointLen = strlen(zf->mountPoint);
@@ -2019,10 +2015,8 @@ TclZipfs_Mount(
}
if (ZipFSCatalogFilesystem(interp, zf, mountPoint, passwd, zipname)
!= TCL_OK) {
- ckfree(zf);
return TCL_ERROR;
}
- ckfree(zf);
return TCL_OK;
}
@@ -2109,7 +2103,6 @@ TclZipfs_MountBuffer(
}
result = ZipFSCatalogFilesystem(interp, zf, mountPoint, NULL,
"Memory Buffer");
- ckfree(zf);
return result;
}