From: simonmar Date: Tue, 28 Mar 2000 08:49:56 +0000 (+0000) Subject: [project @ 2000-03-28 08:49:56 by simonmar] X-Git-Tag: Approximately_9120_patches~4894 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=cee674c3da09b1a8ff796762329d0a48f723caa3;p=ghc-hetmet.git [project @ 2000-03-28 08:49:56 by simonmar] We weren't releasing the memory associated with dead file objects (including the possibly large buffer). This commit fixes that. --- diff --git a/ghc/lib/std/cbits/closeFile.c b/ghc/lib/std/cbits/closeFile.c index f144c41..3c3eb4a 100644 --- a/ghc/lib/std/cbits/closeFile.c +++ b/ghc/lib/std/cbits/closeFile.c @@ -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; } diff --git a/ghc/lib/std/cbits/freeFile.c b/ghc/lib/std/cbits/freeFile.c index ffe5723..aecf498 100644 --- a/ghc/lib/std/cbits/freeFile.c +++ b/ghc/lib/std/cbits/freeFile.c @@ -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; }