summaryrefslogtreecommitdiffstats
path: root/generic/tclIOUtil.c
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2002-05-13 13:19:59 (GMT)
committervincentdarley <vincentdarley>2002-05-13 13:19:59 (GMT)
commit18b4a36a1a37a62808c9caa0b3d6eb1882c3ed65 (patch)
tree54e38ca856778879fde314424eee2707f709d2f0 /generic/tclIOUtil.c
parentffae2997ee93cabad7b2024b2a18767ade8b4790 (diff)
downloadtcl-18b4a36a1a37a62808c9caa0b3d6eb1882c3ed65.zip
tcl-18b4a36a1a37a62808c9caa0b3d6eb1882c3ed65.tar.gz
tcl-18b4a36a1a37a62808c9caa0b3d6eb1882c3ed65.tar.bz2
memory cleanup
Diffstat (limited to 'generic/tclIOUtil.c')
-rw-r--r--generic/tclIOUtil.c56
1 files changed, 54 insertions, 2 deletions
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).
*