curl / Mailing Lists / curl-users / Single Mail

curl-users

Re: valgrind detects memory leaks when using libcurl

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 9 Mar 2017 16:08:12 +0100

On Thu, Mar 09, 2017 at 01:31:54PM +0100, Ralph Nemitz wrote:
> Here is the write callback:
>
> struct MemoryStruct {
> char *memory;
> size_t size;
> };
>
> static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb,
> void *userp)
> {
> size_t realsize = size * nmemb;
> struct MemoryStruct *mem = (struct MemoryStruct *)userp;
> mem->memory = realloc(mem->memory, mem->size + realsize + 1);
> if(mem->memory == NULL) {
> /* out of memory! */
> printf("not enough memory (realloc returned NULL)\n");
> return 0;
> }

This will leak memory in an OOM condition, but that's likely not what's
happening here.

>
> memcpy(&(mem->memory[mem->size]), contents, realsize);
> mem->size += realsize;
> mem->memory[mem->size] = 0;
>
> return realsize;
> }
>
> But even if I don't use it, the errcors occur (during valgrind runs):
>
> ====1455== Conditional jump or move depends on uninitialised value(s)
> ==1455== at 0x65E9A52: ecp_nistz256_point_add (in
> /usr/lib/libcrypto.so.1.0.0)

This one is expected, as the FAQ entry you mention explains.

> ==1455== by 0x4C3EB7521D01E48F: ???
> ==1455== by 0x1D2935B619EF1A6F: ???
> ==1455== by 0xF2B0C63745A951B6: ???
> ==1455== by 0x1ED08D0F3ECB45B7: ???
> ==1455== by 0x305B042E8D3C36D5: ???
> ==1455== by 0x28E345CC0597BDA9: ???
> ==1455== by 0x1089364271DCAC0E: ???
> ==1455== by 0xAD949019C0D7573D: ???
> ==1455== by 0xCAC3B5147917FCDB: ???
> ==1455== by 0x6D734C6B92FC4BC: ???
> ==1455== by 0x927054D13A73A53E: ???
> ==1455== Uninitialised value was created by a stack allocation
> ==1455== at 0x55B4770: ??? (in /usr/lib/libcurl.so.4.4.0)
> ==1455==
> ==1455==
> ==1455== More than 1000 different errors detected. I'm not reporting any
> more.
> ==1455== Final error counts will be inaccurate. Go fix your program!
> ==1455== Rerun with --error-limit=no to disable this cutoff. Note
> ==1455== that errors may occur in your program without prior warning from
> ==1455== Valgrind, because errors are no longer being displayed.
> ==1455==
>
>
> After I finished valgrind:
>
> ==1455== 3956 errors in context 1000 of 1000:
> ==1455== Conditional jump or move depends on uninitialised value(s)
> ==1455== at 0x4C31CA6: rawmemchr (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1455== by 0x5895421: _IO_str_init_static_internal (in
> /usr/lib/libc-2.24.so)
> ==1455== by 0x58845E6: __isoc99_vsscanf (in /usr/lib/libc-2.24.so)
> ==1455== by 0x5884586: __isoc99_sscanf (in /usr/lib/libc-2.24.so)
> ==1455== by 0x55BC4F4: ??? (in /usr/lib/libcurl.so.4.4.0)
> ==1455== by 0x55D4F07: ??? (in /usr/lib/libcurl.so.4.4.0)
> ==1455== by 0x55E015D: ??? (in /usr/lib/libcurl.so.4.4.0)
> ==1455== by 0x55E0C50: curl_multi_perform (in /usr/lib/libcurl.so.4.4.0)
> ==1455== by 0x55D6ABF: curl_easy_perform (in /usr/lib/libcurl.so.4.4.0)
> ==1455== by 0x404268: main (dcs_data_transfer.c:744)
> ==1455==
> ==1455== ERROR SUMMARY: 34862 errors from 1000 contexts (suppressed: 0 from
> 0)

This one isn't in OpenSSL, but it's not clear if the problem is in libc or
libcurl. Try compiling with debug symbols enabled to get a better stack trace,
and, as I suggested, try using the gdb integration in Valgrind to see exactly
what data is getting passed into sscanf that it doesn't like.

>
> Is it possible, that this has to do how I have compiled the openssl library
> (https://www.openssl.org/docs/faq.html#PROG14) ?
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-03-09