From 18b4a36a1a37a62808c9caa0b3d6eb1882c3ed65 Mon Sep 17 00:00:00 2001 From: vincentdarley Date: Mon, 13 May 2002 13:19:59 +0000 Subject: memory cleanup --- ChangeLog | 9 +++++++++ generic/tclEvent.c | 8 +++++++- generic/tclIOUtil.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-- generic/tclInt.h | 3 ++- win/tclWinChan.c | 17 ++++++++-------- 5 files changed, 81 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d3dcf2..e3733c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2002-05-13 Vince Darley + + * generic/tclEvent.c: + * generic/tclIOUtil.c: + * generic/tclInt.h: clean up all memory allocated by the + filesystem, via introduction of 'TclFinalizeFilesystem'. + Fix bad comment also. [Fixes 555078 and 'fs' part of 543549] + * win/tclWinChan.c: fix comment referring to wrong function. + 2002-05-10 Don Porter * tests/load.test: diff --git a/generic/tclEvent.c b/generic/tclEvent.c index 4e24e72..6d16bf7 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -11,7 +11,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEvent.c,v 1.20 2002/03/20 22:47:36 dgp Exp $ + * RCS: @(#) $Id: tclEvent.c,v 1.21 2002/05/13 13:20:00 vincentdarley Exp $ */ #include "tclInt.h" @@ -843,6 +843,12 @@ Tcl_Finalize() */ TclFinalizeLoad(); + + /** + * Finalizing the filesystem must come after anything which + * might conceivably interact with the 'Tcl_FS' API. + */ + TclFinalizeFilesystem(); /* * There shouldn't be any malloc'ed memory after this. diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index d3d16bc..27df363 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -17,7 +17,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIOUtil.c,v 1.42 2002/05/13 12:31:32 vincentdarley Exp $ + * RCS: @(#) $Id: tclIOUtil.c,v 1.43 2002/05/13 13:20:00 vincentdarley Exp $ */ #include "tclInt.h" @@ -409,6 +409,9 @@ static Tcl_Filesystem nativeFilesystem = { * uses of Tcl without a native filesystem, we may in the future wish * to modify the current approach of hard-coding the native filesystem * in the lookup list 'filesystemList' below. + * + * We initialize the record so that it thinks one file uses it. This + * means it will never be freed. */ static FilesystemRecord nativeFilesystemRecord = { NULL, @@ -554,12 +557,61 @@ FsReleaseIterator(void) { /* *---------------------------------------------------------------------- * + * TclFinalizeFilesystem -- + * + * Clean up the filesystem. After this, calls to all Tcl_FS... + * functions will fail. + * + * Results: + * None. + * + * Side effects: + * Frees any memory allocated by the filesystem. + * + *---------------------------------------------------------------------- + */ + +void +TclFinalizeFilesystem() { + /* + * Assumption that only one thread is active now. Otherwise + * we would need to put various mutexes around this code. + */ + + if (cwdPathPtr != NULL) { + Tcl_DecrRefCount(cwdPathPtr); + cwdPathPtr = NULL; + } + + /* Remove all filesystems, freeing any allocated memory */ + while (filesystemList != NULL) { + FilesystemRecord *tmpFsRecPtr = filesystemList->nextPtr; + if (filesystemList->fileRefCount > 1) { + /* + * We are freeing a filesystem which actually has + * path objects still around which belong to it. + * This is probably bad, but since we are exiting, + * we don't do anything about it. + */ + } + /* The native filesystem is static, so we don't free it */ + if (filesystemList != &nativeFilesystemRecord) { + ckfree((char *)filesystemList); + } + filesystemList = tmpFsRecPtr; + } + /* Now filesystemList is NULL */ +} + +/* + *---------------------------------------------------------------------- + * * Tcl_FSRegister -- * * Insert the filesystem function table at the head of the list of * functions which are used during calls to all file-system * operations. The filesystem will be added even if it is - * already in the list. (You can use TclFilesystemData to + * already in the list. (You can use Tcl_FSData to * check if it is in the list, provided the ClientData used was * not NULL). * diff --git a/generic/tclInt.h b/generic/tclInt.h index a813e41..7346bd2 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclInt.h,v 1.86 2002/04/24 20:36:05 hobbs Exp $ + * RCS: @(#) $Id: tclInt.h,v 1.87 2002/05/13 13:20:00 vincentdarley Exp $ */ #ifndef _TCLINT @@ -1685,6 +1685,7 @@ EXTERN void TclFinalizeEncodingSubsystem _ANSI_ARGS_((void)); EXTERN void TclFinalizeEnvironment _ANSI_ARGS_((void)); EXTERN void TclFinalizeExecution _ANSI_ARGS_((void)); EXTERN void TclFinalizeIOSubsystem _ANSI_ARGS_((void)); +EXTERN void TclFinalizeFilesystem _ANSI_ARGS_((void)); EXTERN void TclFinalizeLoad _ANSI_ARGS_((void)); EXTERN void TclFinalizeMemorySubsystem _ANSI_ARGS_((void)); EXTERN void TclFinalizeNotifier _ANSI_ARGS_((void)); diff --git a/win/tclWinChan.c b/win/tclWinChan.c index d850b62..ad10251 100644 --- a/win/tclWinChan.c +++ b/win/tclWinChan.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinChan.c,v 1.21 2002/03/15 01:10:19 mdejong Exp $ + * RCS: @(#) $Id: tclWinChan.c,v 1.22 2002/05/13 13:20:00 vincentdarley Exp $ */ #include "tclWinInt.h" @@ -1215,18 +1215,19 @@ TclWinOpenFileChannel(handle, channelName, permissions, appendMode) /* *---------------------------------------------------------------------- * - * TclWinOpenFileChannel -- + * TclWinFlushDirtyChannels -- * - * Constructs a File channel for the specified standard OS handle. - * This is a helper function to break up the construction of - * channels into File, Console, or Serial. + * Flush all dirty channels to disk, so that requesting the + * size of any file returns the correct value. * * Results: - * Returns the new channel, or NULL. + * None. * * Side effects: - * May open the channel and may cause creation of a file on the - * file system. + * Information is actually written to disk now, rather than + * later. Don't call this too often, or there will be a + * performance hit (i.e. only call when we need to ask for + * the size of a file). * *---------------------------------------------------------------------- */ -- cgit v0.12