cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: about the bug of glibc detected free invalid pointer

From: yi xia <max.xiayi_at_gmail.com>
Date: Wed, 13 Feb 2008 17:15:17 +0800

Hi Daniel
On the tutorial.html, there is a suggestion that if using libcurl in
multithread environment, we should set NOSIGNAL to be true. I guess my
problem may come from
curl_easy_setopt(curl, CURLOPT_TIMEOUT, mytimeout);
IF we
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
then the siglongjmp is not enabled, which is used to realize
CURLOPT_TIMEOUT.

BUT, I STILL WANNA KNOW WHY ON EARTH MY SIMPLE TEST CODE WILL CAUSE
SEGMENTATION FAULT.

and as your suggestion, I use valgrind to check memory, the following is the
result, can you give me some points?

valgrind --leak-check=full --show-reachable=yes ./a.out
==25765== Memcheck, a memory error detector.
==25765== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==25765== Using LibVEX rev 1804, a library for dynamic binary translation.
==25765== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==25765== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==25765== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==25765== For more details, rerun with: -v
==25765==
before ==================Curl_resolv================
before return CURLRESOLV_ERROR
in hostip.c hostname ============www.xiayi345cheng.com============
hostname ===========www.xiayi345cheng.com
=================yes, we are timeout xiayi================
after==================Curl_resolv================
==25765==
==25765== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 40 from 1)
==25765== malloc/free: in use at exit: 10,324 bytes in 10 blocks.
==25765== malloc/free: 1,907 allocs, 1,897 frees, 83,540 bytes allocated.
==25765== For counts of detected errors, rerun with: -v
==25765== searching for pointers to 10 not-freed blocks.
==25765== checked 470,004 bytes.
==25765==
==25765== 288 bytes in 8 blocks are still reachable in loss record 1 of 3
==25765== at 0x4005828: malloc (vg_replace_malloc.c:207)
==25765== by 0x372CC5D: (within /lib/libcrypto.so.0.9.8b)
==25765== by 0x372D2DE: CRYPTO_malloc (in /lib/libcrypto.so.0.9.8b)
==25765== by 0x376F870: ENGINE_new (in /lib/libcrypto.so.0.9.8b)
==25765== by 0x37737DB: ENGINE_load_dynamic (in /lib/libcrypto.so.0.9.8b)
==25765== by 0x3771D76: ENGINE_load_builtin_engines (in
/lib/libcrypto.so.0.9.8b)
==25765== by 0x404455D: Curl_ossl_init (ssluse.c:560)
==25765== by 0x405C41A: Curl_ssl_init (sslgen.c:159)
==25765== by 0x405076C: curl_global_init (easy.c:226)
==25765== by 0x8048A90: handleLogin(void*) (in
/home/xiayi/MyTest/curltest/a.out)
==25765== by 0x4A82FA: start_thread (in /lib/libpthread-2.6.so)
==25765== by 0x3EB93D: clone (in /lib/libc-2.6.so)
==25765==
==25765==
==25765== 1,024 bytes in 1 blocks are still reachable in loss record 2 of 3
==25765== at 0x4005828: malloc (vg_replace_malloc.c:207)
==25765== by 0x400596C: realloc (vg_replace_malloc.c:429)
==25765== by 0x4A8E09: pthread_create@@GLIBC_2.1 (in /lib/libpthread-
2.6.so)
==25765== by 0x8048A59: main (in /home/xiayi/MyTest/curltest/a.out)
==25765==
==25765==
==25765== 9,012 bytes in 1 blocks are definitely lost in loss record 3 of 3
==25765== at 0x4005828: malloc (vg_replace_malloc.c:207)
==25765== by 0x40514B3: curl_docalloc (memdebug.c:162)
==25765== by 0x405B0D7: Curl_getaddrinfo (hostip4.c:153)
==25765== by 0x4028CC7: Curl_resolv (hostip.c:462)
==25765== by 0x4042018: CreateConnection (url.c:4118)
==25765== by 0x404241C: Curl_connect (url.c:4316)
==25765== by 0x404FF7C: Curl_connect_host (transfer.c:2333)
==25765== by 0x40501F4: Curl_perform (transfer.c:2429)
==25765== by 0x4050AF8: curl_easy_perform (easy.c:498)
==25765== by 0x8048B6B: handleLogin(void*) (in
/home/xiayi/MyTest/curltest/a.out)
==25765== by 0x4A82FA: start_thread (in /lib/libpthread-2.6.so)
==25765== by 0x3EB93D: clone (in /lib/libc-2.6.so)
==25765==
==25765== LEAK SUMMARY:
==25765== definitely lost: 9,012 bytes in 1 blocks.
==25765== possibly lost: 0 bytes in 0 blocks.
==25765== still reachable: 1,312 bytes in 9 blocks.
==25765== suppressed: 0 bytes in 0 blocks.

Thanks a lot in advance.
Max
2008/2/7, Daniel Stenberg <daniel_at_haxx.se>:
>
> On Wed, 6 Feb 2008, yi xia wrote:
>
> > Anybody can give me some hints?
>
> In addition to what Dan F already mentioned, I suggest you run your
> program
> with valgrind to help pinpointing the problem.
>
> --
> Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
>
Received on 2008-02-13