Silakan minum, berani?

Terbayang di jaman dulu, ketika kebanyakan orang adalah petani.
Banyak orang menyuguhkan kendi di depan rumah, secuil sedekah bagi yang haus.

Tapi kalo hal itu ada di jaman ini, beranikah anda meminumnya ? 🙂

Berani minum ?

Advertisements

pthread_create valgrind memory leak solved

Its look like pthread_detach() and pthread_create()   is couple like free() to  malloc() . So … dont forget !

#include <stdio.h>
#include <pthread.h>

// unmark pthread_detach(), memory leak will be gone

void* process( void* data ) {
printf( “hello world\n” );
}

main() {
pthread_t th;
pthread_create( &th, NULL, process, NULL );
sleep( 1 );
// pthread_detach( th );
return 0;
}

/*

$ valgrind –tool=memcheck –leak-check=full –show-reachable=yes ./a.out

==23782== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1
==23782== at 0x4C1DCBF: calloc (vg_replace_malloc.c:279)
==23782== by 0x400FDF2: _dl_allocate_tls (in /lib64/ld-2.5.so)
==23782== by 0x4E28A33: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.5.so)
==23782== by 0x4005BF: main (thsimple.c:11)
==23782==
==23782== LEAK SUMMARY:
==23782== definitely lost: 0 bytes in 0 blocks.
==23782== possibly lost: 272 bytes in 1 blocks.
==23782== still reachable: 0 bytes in 0 blocks.
==23782== suppressed: 0 bytes in 0 blocks.

*/

Links:

http://sourceware.org/ml/glibc-bugs/2007-04/msg00036.html

http://www.linuxquestions.org/questions/programming-9/memory-leak-in-pthread-591263/

http://sources.redhat.com/bugzilla/show_bug.cgi?id=5171