[project @ 2000-03-28 08:49:56 by simonmar]
authorsimonmar <unknown>
Tue, 28 Mar 2000 08:49:56 +0000 (08:49 +0000)
committersimonmar <unknown>
Tue, 28 Mar 2000 08:49:56 +0000 (08:49 +0000)
We weren't releasing the memory associated with dead file objects
(including the possibly large buffer).  This commit fixes that.

ghc/lib/std/cbits/closeFile.c
ghc/lib/std/cbits/freeFile.c

index f144c41..3c3eb4a 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: closeFile.c,v 1.8 2000/03/14 01:52:25 sof Exp $
+ * $Id: closeFile.c,v 1.9 2000/03/28 08:49:56 simonmar Exp $
  *
  * hClose Runtime Support
  */
@@ -60,6 +60,14 @@ closeFile(StgForeignPtr ptr, StgInt flush_buf)
        
     }
 
+    /* Free the buffer straight away.  We can't free the file object
+     * itself until the finalizer runs.
+     */
+    if ( fo->buf != NULL ) {
+       free(fo->buf);
+       fo->buf = NULL;
+    }
+
     /* Closing file descriptors that refer to standard channels
        is problematic, so we back off from doing this by default,
        just closing them at the Handle level. If you insist on
@@ -89,6 +97,8 @@ closeFile(StgForeignPtr ptr, StgInt flush_buf)
        }
       }
     }
+
     fo->fd = -1;
+
     return 0;
 }
index ffe5723..aecf498 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
  *
- * $Id: freeFile.c,v 1.8 1999/11/26 16:25:56 simonmar Exp $
+ * $Id: freeFile.c,v 1.9 2000/03/28 08:49:56 simonmar Exp $
  *
  * Giving up files
  */
@@ -65,7 +65,11 @@ freeFileObject(StgForeignPtr ptr)
          * (via closeFile()), we will have given
         * up our process lock, so we break off and just return.
          */
-       return;
+      if ( fo->buf != NULL ) {
+       free(fo->buf);
+      }
+      free(fo);
+      return;
     }
 
     if (fo->buf != NULL && fo->bufWPtr > 0) {
@@ -84,6 +88,11 @@ freeFileObject(StgForeignPtr ptr)
 #endif
     /* Error or no error, we don't care.. */
 
+    if ( fo->buf != NULL ) {
+       free(fo->buf);
+    }
+    free(fo);
+
     return;
 }