Description of Problem: fprintf leaks memory by the length of data written to a file. It does not happen on redhat 6.2. Version-Release number of selected component (if applicable): How Reproducible: It's reproducible. Steps to Reproduce: 1. 2. 3. Actual Results: Expected Results: Additional Information:
Correction: The 'memory leak' size is not the length of data, but about 4k per fprintf according to "vmstat -n 1". My small test program is following: char log_message[256]=""; FILE *rep; int main( int argc, char *argv[] ) { int rc=0; int i=0; int count=0; char log_message[256]=""; count = atoi(argv[1]); memset(log_message,256,0); rep = fopen("service.log", "a+"); if (rep == NULL ){ printf (log_message, " ** Unable to open service.log"); exit(-1); } for (i=0;i<count;i++){ strcpy(log_message,"abcdefghijklmnopqrstuvwxyz11111222223333344444555556666677777888889999900000aaaaabbbbbcccccdddddeeeeeff fffggggghhhhhiiiiijjjjjkkkkklllll"); fprintf( rep, "%05d%s\n", i, log_message); fflush(rep); sleep(1); } rc=fclose(rep); if (rc){ printf (" ** Unable to close service.log"); exit(-1); } }
1) fprintf() is not a kernel systemcall 2) Welcome to disk caching
Correction again: The size of memory leak is about 4k from 10 fprintf's approximately.
Sorry, I don't see any leaks. I've commented out the sleep call and run it under strace. After startup there are no other syscalls than write until the loop ends (see strace output). If libc leaked memory, there would be mmap or brk syscalls in between.
Thank you for your research. I saw 4k memory leak after 10-15 seconds. I am not sure how long you ran strace. I tested 'write' system call instead of 'fprintf. It showed same memory leak also. I am still wondering why this problem does not happen on redhat 6.2 machines. (tried two redhat 6.2 machines.) Do you think my redhat 7.1 configuration about 'file write' is incorrect? Would you give me any suggestions to specify good values for the 'file write'.
Found a web site describing fprintf memory leak, but the suggested solution does not work for me. I don't know if their system is linux. The site has the title, "[uCsimm] General memory problem". Tested printf instead of fprintf. No memory leak was shown.