P
Pietro Cerutti
Hi group,
I just noticed that a malloc w/out relative free occurs in the standard
C library (or at least, on my implementation of it).
int main(void) {
printf("%s\n", "Hello");
return (0);
}
4096 bytes in 1 blocks are still reachable in loss record 1 of 1
at 0x3C03B18F: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so)
by 0x3C116FD2: __smakebuf (in /lib/libc.so.6)
by 0x3C116E77: __swsetup (in /lib/libc.so.6)
by 0x3C10BF7F: __vfprintf (in /lib/libc.so.6)
Now, if I modify the test program as follows:
int main(void) {
printf("%s\n", "Hello");
fclose(stdout);
return (0);
}
and I recompile it:
==1846== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1846== malloc/free: 1 allocs, 1 frees, 4096 bytes allocated.
My question are the following:
- is it normal or is it likely to be a bug in my implementation of the C
library?
- is it safe to fclose stdout before returning to the OS?
Thanks!
I just noticed that a malloc w/out relative free occurs in the standard
C library (or at least, on my implementation of it).
#include <stdio.h>cat test.c
int main(void) {
printf("%s\n", "Hello");
return (0);
}
[snip bla bla]gcc -o test test.c
valgrind --leak-check=yes --show-reachable=yes -v ./test
4096 bytes in 1 blocks are still reachable in loss record 1 of 1
at 0x3C03B18F: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so)
by 0x3C116FD2: __smakebuf (in /lib/libc.so.6)
by 0x3C116E77: __swsetup (in /lib/libc.so.6)
by 0x3C10BF7F: __vfprintf (in /lib/libc.so.6)
Now, if I modify the test program as follows:
#include <stdio.h>cat test.c
int main(void) {
printf("%s\n", "Hello");
fclose(stdout);
return (0);
}
and I recompile it:
==1846== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)gcc -o test test.c
valgrind --leak-check=yes --show-reachable=yes -v ./test
==1846== malloc/free: in use at exit: 0 bytes in 0 blocks.
==1846== malloc/free: 1 allocs, 1 frees, 4096 bytes allocated.
My question are the following:
- is it normal or is it likely to be a bug in my implementation of the C
library?
- is it safe to fclose stdout before returning to the OS?
Thanks!