SCIENTIFIC-LINUX-USERS Archives

June 2010

SCIENTIFIC-LINUX-USERS@LISTSERV.FNAL.GOV

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sun, 20 Jun 2010 20:12:20 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (59 lines)
I observed a memory leak (about 20 bytes per iteration) when I ran this 

simple program on my Scientific Linux 5.4 box (kernel version 2.6.18-
128.1.1.e15).

What I did was noting the output of "free -m" before and after I ran the 

program (which loops for 300000). I observed a 6MB increase in memory use
d.  
No error was printed during the run.

If I comment out the 2 fseek statements, then I don't see any memory 
increase.

The file size is about 700KB.

I was wondering if someone can tell me if this is a known issue or if I'm
 
doing something wrong.

Thanks,
Khoa.

======Source file, compiled with gcc=========

#include <stdio.h>
#include <errno.h>

int main()
{
   FILE * ptr = NULL;
   int count = 0;
 
   ptr = fopen("myBinaryFile","r");
   while (ptr != NULL &&amp; count++ < 300000)
   {
        usleep(1000);

        if (fseek(ptr, 0, SEEK_END))
                printf("Error 1: %d\n", errno);
        if (fseek(ptr, 0, SEEK_SET))
                printf("Error 2: %d\n", errno);

        if (fclose(ptr))
                break;

        usleep(10000);

        ptr = fopen("myBinaryFile","r");
   }
   
    fclose(ptr);
        
    if (count >= 300000)
       print("Success\n");

    return 0;
}

ATOM RSS1 RSS2