J
Joshua Maurice
The C library on all platforms has memory leaks? Prove it.
I strive to write leak free code for any definition of leak. As I have
already said Microsoft agree with me on the definition of a leak so it
is not a "Leigh Johnston memory leak" but a "memory leak". End of
discussion.
Curious. I jumped to conclusions. I just tested it on my linux box.
Repeated loading and unloading of libc and the c++ std lib does not
result in increasing process size. I was wrong.
Test code:
//foo.c
int main();
void _start()
{
main();
asm("movl %eax,%ebx");
asm("movl $1, %eax");
asm("int $0x80");
}
#include <dlfcn.h>
int main()
{
for (;
{
void* libcpp = dlopen("/usr/lib64/libstdc++.so.6", RTLD_NOW |
RTLD_GLOBAL);
if ( ! libcpp)
return 7;
if (dlclose(libcpp))
return 8;
}
Compile and link command:
gcc foo.c -nostdlib -lgcc -ldl
In another test (not shown), I even malloc-ed a piece of memory with
malloc from dlsym, then free-ed it with free from dlsym, once per
loading of libc, in a tight loop. Again, no increase in process size.
This is most interesting.