summaryrefslogtreecommitdiffstats
path: root/generic/tclIOUtil.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2012-06-22 16:50:23 (GMT)
committerdgp <dgp@users.sourceforge.net>2012-06-22 16:50:23 (GMT)
commit2c9e58a0fc44937a2605b87fd08a174e75e6bd00 (patch)
tree30aae398e350b3fbcdfeeccb5120cf4d6da647a2 /generic/tclIOUtil.c
parentffda352cbe3ef13481ae52a01a3da337ad3778fc (diff)
parentfc25ed040a2abd529c7aa70e95e5a2981a13c92a (diff)
downloadtcl-2c9e58a0fc44937a2605b87fd08a174e75e6bd00.zip
tcl-2c9e58a0fc44937a2605b87fd08a174e75e6bd00.tar.gz
tcl-2c9e58a0fc44937a2605b87fd08a174e75e6bd00.tar.bz2
Revise the order of memory free, so that bugs that attempt to access freed memory
are more likely to segfault and not remain hidden.
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r--generic/tclIOUtil.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index f466ca8..577af87 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -420,6 +420,7 @@ FsThrExitProc(
while (fsRecPtr != NULL) {
tmpFsRecPtr = fsRecPtr->nextPtr;
if (--fsRecPtr->fileRefCount <= 0) {
+ fsRecPtr->fsPtr = NULL;
ckfree(fsRecPtr);
}
fsRecPtr = tmpFsRecPtr;
@@ -528,7 +529,7 @@ static void
FsRecacheFilesystemList(void)
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&tclFsDataKey);
- FilesystemRecord *fsRecPtr, *tmpFsRecPtr = NULL;
+ FilesystemRecord *fsRecPtr, *tmpFsRecPtr = NULL, *toFree = NULL;
/*
* Trash the current cache.
@@ -538,7 +539,9 @@ FsRecacheFilesystemList(void)
while (fsRecPtr != NULL) {
tmpFsRecPtr = fsRecPtr->nextPtr;
if (--fsRecPtr->fileRefCount <= 0) {
- ckfree(fsRecPtr);
+ fsRecPtr->fsPtr = NULL;
+ fsRecPtr->nextPtr = toFree;
+ toFree = fsRecPtr;
}
fsRecPtr = tmpFsRecPtr;
}
@@ -574,6 +577,12 @@ FsRecacheFilesystemList(void)
fsRecPtr = fsRecPtr->prevPtr;
}
+ while (toFree) {
+ FilesystemRecord *next = toFree->nextPtr;
+ ckfree(toFree);
+ toFree = next;
+ }
+
/*
* Make sure the above gets released on thread exit.
*/