|
From: maverick m. <muj...@gm...> - 2008-10-06 03:30:50
|
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) Regards, |
|
From: Andreas B. <ber...@in...> - 2008-10-06 06:57:36
|
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.
|
|
From: Bart V. A. <bar...@gm...> - 2008-10-07 07:59:21
|
On Mon, Oct 6, 2008 at 5:30 AM, maverick me <muj...@gm...> wrote: > I am trying valgrind to test memory leak. It would help a lot if you could post the source code of a small program that allows to reproduce the problem you described. Bart. |
|
From: Scott G. <sgi...@su...> - 2008-10-07 16:23:29
|
"maverick me" <muj...@gm...> writes: > 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/[1]ld-2.3.4.so) > ==32589== by 0x6E291E: [2]pthread_create@@GLIBC_2.1 (in > /lib/tls/[3]libpthread-2.3.4.so) I had similar leaks which were solved by being careful to always pthread_join() or pthread_detach() the thread. If that doesn't help, maybe a short snippet of code to reproduce the problem would be helpful. ----Scott. |