maverick me wrote:
> Hi,
>
> I am trying valgrind to test memory leak.
> Valgrind showing memory leak when I pass a pointer from heap as 4th argument
> to pthread_create.
>
> ==32589== 144 bytes in 1 blocks are definitely lost in loss record 34 of 74
> ==32589== at 0x4005D85: calloc (vg_replace_malloc.c:397)
> ==32589== by 0x57571A: _dl_allocate_tls (in /lib/ld-2.3.4.so)
> ==32589== by 0x6E291E: pthread_create@@GLIBC_2.1 (in /lib/tls/
> libpthread-2.3.4.so)
I cannot verify this with glibc 2.7, libpthread 2.7 (valgrind 3.3.1).
Maybe your versions of glibc, libpthread are buggy? What was the program
with which you tested valgrind?
test.c:
-------8<---------
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
void* start(void* arg) {
puts(arg);
return (void*) 0;
}
int main() {
pthread_t thread;
int err;
const size_t SIZE=15;
char* msg = calloc(SIZE, sizeof(char));
strncpy(msg, "heap thread", SIZE);
if ((err = pthread_create(&thread, NULL, start, msg))) {
puts("thread creation failed");
}
pthread_join(thread, NULL);
free(msg);
}
-------->8--------
$ cc -lpthread test.c -o test
$ valgrind ./test
==21812== Memcheck, a memory error detector.
==21812== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==21812== Using LibVEX rev 1854, a library for dynamic binary translation.
==21812== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==21812== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation
framework.
==21812== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==21812== For more details, rerun with: -v
==21812==
heap thread
==21812==
==21812== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==21812== malloc/free: in use at exit: 0 bytes in 0 blocks.
==21812== malloc/free: 2 allocs, 2 frees, 151 bytes allocated.
==21812== For counts of detected errors, rerun with: -v
==21812== All heap blocks were freed -- no leaks are possible.
Cheers,
Andreas.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users