diff options
author | dgp <dgp@users.sourceforge.net> | 2012-06-22 16:50:23 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2012-06-22 16:50:23 (GMT) |
commit | 2c9e58a0fc44937a2605b87fd08a174e75e6bd00 (patch) | |
tree | 30aae398e350b3fbcdfeeccb5120cf4d6da647a2 /generic | |
parent | ffda352cbe3ef13481ae52a01a3da337ad3778fc (diff) | |
parent | fc25ed040a2abd529c7aa70e95e5a2981a13c92a (diff) | |
download | tcl-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')
-rw-r--r-- | generic/tclIOUtil.c | 13 |
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. */ |