[m-dev.] diff: fix memory leak in io.m

Peter Ross peter.ross at miscrit.be
Wed Dec 13 01:03:40 AEDT 2000


Hi,


===================================================================


Estimated hours taken: 40

Fix a memory leak in `io.m'.

io.m:
    Before closing a stream delete the stream_name.  Otherwise their is
    still a live reference to the MercuryFile structure in the
    stream_name tree.  Hence the MercuryFile structure will never be garbage
    collected.


Index: io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.213
diff -u -r1.213 io.m
--- io.m	2000/11/23 01:59:55	1.213
+++ io.m	2000/12/12 13:55:32
@@ -3494,25 +3494,24 @@
 	update_io(IO0, IO);
 ").
 
-:- pragma c_code(io__close_input(Stream::in, IO0::di, IO::uo),
-		[may_call_mercury, thread_safe], "
-	mercury_close((MercuryFile *) Stream);
-	update_io(IO0, IO);
-").
+io__close_input(Stream) -->
+	io__delete_stream_name(Stream),
+	io__close_stream(Stream).
 
-:- pragma c_code(io__close_output(Stream::in, IO0::di, IO::uo),
-		[may_call_mercury, thread_safe], "
-	mercury_close((MercuryFile *) Stream);
-	update_io(IO0, IO);
-").
+io__close_output(Stream) -->
+	io__delete_stream_name(Stream),
+	io__close_stream(Stream).
 
-:- pragma c_code(io__close_binary_input(Stream::in, IO0::di, IO::uo),
-		[may_call_mercury, thread_safe], "
-	mercury_close((MercuryFile *) Stream);
-	update_io(IO0, IO);
-").
+io__close_binary_input(Stream) -->
+	io__delete_stream_name(Stream),
+	io__close_stream(Stream).
 
-:- pragma c_code(io__close_binary_output(Stream::in, IO0::di, IO::uo),
+io__close_binary_output(Stream) -->
+	io__delete_stream_name(Stream),
+	io__close_stream(Stream).
+
+:- pred io__close_stream(stream::in, io__state::di, io__state::uo) is det.
+:- pragma c_code(io__close_stream(Stream::in, IO0::di, IO::uo),
 		[may_call_mercury, thread_safe], "
 	mercury_close((MercuryFile *) Stream);
 	update_io(IO0, IO);

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list