[uCsimm] Memory leak caused by fopen

From: Ian Leonard (ileonard@ntlworld.com)
Date: Tue Jun 05 2001 - 16:05:30 EDT


I have a program with a memory leak. Every 4 or 5 iterations, memory
usage goes up by 4096 bytes. Does anybody know why this should be?

I see from the uClib source that fopen allocates a buffer for the
data when it opens. I thought that this should be done on the first
i/o operation. It looks like fclose deallocates memory (although it
obviously doesn't) and setvbuf () doesn't help either.

Thanks.

int
main ()
{
     FILE *fp;

     while ( 1) {
          
          if ( ( fp = fopen ( DATAFILE, "w")) == NULL) {
               perror ( DATAFILE);
               return 1;
          }

          fclose ( fp);
     }
}

-- 
Ian Leonard                  
eMail: ileonard@ntlworld.com
Phone: +44 (0)1865 765273       Fax: +44 (0)1865 765280

Please ignore spelling and punctuation - I did. This message resent by the ucsimm@uclinux.com list server http://www.uClinux.com/



This archive was generated by hypermail 2b30 : Sun Apr 07 2002 - 00:01:43 EST