Hi Jakub,

Thanks for the info. 
I did not dig that deep into code. Please go ahead with your patch.

Sincerely yours,


Jinfei Fan


Date: Fri, 1 Nov 2013 21:25:46 +0100
From: [email protected]
To: [email protected]
Subject: Re: [HelenOS-devel] bug patch

Hi Jinfei Fan,
 
On 11/01/2013 04:04 AM, Fan Jinfei wrote:
> 1. file buffer memory leak
 
=== modified file 'uspace/lib/c/generic/io/io.c'
--- uspace/lib/c/generic/io/io.c        2013-01-24 13:55:04 +0000
+++ uspace/lib/c/generic/io/io.c        2013-10-31 17:49:35 +0000
@@ -309,6 +309,9 @@
        
        if (stream->fd >= 0)
                rc = close(stream->fd);
+
+       if (stream->buf != NULL)
+               free(stream->buf);
        
        list_remove(&stream->link);
 
 
The solution is probably not that straightforward as it may seem,
because setbuf() and setvbuf() may be called by applications and they
may use a static buffer. So blindly freeing the buffer would not work in
some cases.
 
I tried to come up with a patch that would honour this possibility. The
patch is attached to this mail. The idea is to distinguish between an
internally allocated buffer and a buffer which came from the outside.
Internally allocated buffer gets deallocated when the stream is closed,
while the externally allocated buffers are never deallocated by the library.
 
Comments?
 
Jakub

_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/listinfo/helenos-devel                                    
  
_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/listinfo/helenos-devel

Reply via email to