Commit cee674c3 authored by simonmar's avatar simonmar
Browse files

[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.
parent 80b09767
/*
* (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;
}
/*
* (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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment