Valgrind detects memory leaks when using libcurl (no ssl)

In my C program, I use some basic libcurl functions. Today I ran valgrind to check for memory leaks, and valgrind went crazy reporting a few errors.

I traced it mainly to:

CURL *curl; CURLcode res; curl = curl_easy_init(); // ... curl_easy_cleanup(curl); 

If I completely remove the code that libcurl uses, valgrind does not report any errors.

I already read that there are some problems using valgrind with libcurl and ssl, but I do not take any https addresses, etc.

What can I do? Can I make valgrind shut up about libcurl errors (possible false positives?) And report only errors from my code? Due to the sheer number of errors, despite the simplest use of libcurl, the output of valgrind is rather confusing.

Unfortunately, I don't have debugging built from libcurl, so valgrind does not even report the line / file numbers where it detected leaks. Error messages look like this:

 ==27330== ==27330== HEAP SUMMARY: ==27330== in use at exit: 34,960 bytes in 2,406 blocks ==27330== total heap usage: 20,130 allocs, 17,724 frees, 2,511,576 bytes allocated ==27330== ==27330== 40 (20 direct, 20 indirect) bytes in 1 blocks are definitely lost in loss record 383 of 445 ==27330== at 0x4025BD3: malloc (vg_replace_malloc.c:236) ==27330== by 0x4B173FD: ??? ==27330== by 0x4B17A8B: ??? ==27330== by 0x4B84957: ??? ==27330== by 0x4B849FD: ??? ==27330== by 0x4B72814: ??? ==27330== by 0x4B734C1: ??? ==27330== by 0x4B78DE2: ??? ==27330== by 0x4B7524B: ??? ==27330== by 0x49B2F76: ??? ==27330== by 0x49C9ECB: ??? ==27330== by 0x49BC96A: ??? ... 
+4
source share
6 answers

I know this answer comes a year later, but someone may still be useful. After calling curl_easy_cleanup(curl) try adding a call to curl_global_cleanup() .

It worked for me.

+6
source

If you start with the first libcurl (simple.c) example, they do not call curl_global_init(long flags) and curl_global_cleanup() at the end, and valgrind will report potential problems. As indicated in the libcurl docs, you MUST call BOTH curl_global_init and curl_global_cleanup . I myself made sure that this solves the problem; valgrind will report that all heap blocks have been freed.

+4
source

libcurl does not flow, but it can use methods that will signal valgrind. So, to repeat from other answers, what are the errors that valgrind reports?

I do not expect you to have libcurl sources, but if so, where are the valgrind errors pointing to you?

+2
source

What mistakes do you really get?

And just as important - is there a static sum leak or do they grow over time? A small one-time static leak is much less important than what flows over time.

It is also possible that this is a false positive from Valgrind; Depends on the specific errors and where you see them.

0
source

Most likely valgrind is just wrong about libcurl . Often for such libraries, it does not see one end of the distribution / release correctly and gets confused. A good OS distribution should provide you with “suppression” files for this, but obviously you didn’t. You can handle this with the --suppressions and --gen-suppressions options, or even put such things in a configuration file.

0
source

I asked on the mailing list, and no one could tell exactly where my problem is, since I still remain in force that I installed the debug version of the latest version of libcurl, but still I could not see any debug symbols.

Anyway, I set up a new virtual machine and compiled libcurl from the source, and the strange error messages disappeared.

Shame that I did not find anything useful, although I could help others with the same problem ...

0
source

All Articles