본문 바로가기
1.일상다반사

glibc detected free() invalid pointer

by kyuho.choi 2014. 4. 26.
728x90
반응형

In the case of using dynamic memory allocation for application,

Sometimes we faced with memory leak.


=================================

do(

char *buf = malloc(sizeof(buf));

foo(buf); 

free(buf);

}while(1)

=================================


Upper code are looks fine, but when we using structure and many loop syntax

memory leak detected from glibc in free() function.


So, I tried clear buffer before free() function call.


=================================

do(

char *buf = malloc(sizeof(buf));

foo(buf); 

memset(buf,0,sizeof(buf));

free(buf);

}while(1)

=================================


Currently, memleaks are not occur. ;)


** Update **


Glibc free deteced problem are remain, not clear.

So, in Ubuntu with Bash shell environment, setting environment like below.

MALLOC_CHECK_ = 1

MALLOC_CHECK_ = 1 means error generated with STDERR, but not abort program.


728x90
반응형

댓글