curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

libcurl usage - memory error

From: Anass Meskini via curl-library <curl-library_at_lists.haxx.se>
Date: Mon, 18 Sep 2023 09:26:36 -0400

Hi,

I am running the following code to send a post request using the multi API:

> curl_global_init(CURL_GLOBAL_ALL);

   auto* curl = curl_multi_init();
> auto* curl_easy = curl_easy_init();
> curl_easy_setopt(curl_easy, CURLOPT_URL, url.c_str());
> curl_easy_setopt(curl_easy, CURLOPT_POST, 1L);
>
> curl_slist* curl_headers = nullptr;
> for (auto& h : headers)
> curl_headers = curl_slist_append(curl_headers, h.c_str());
> curl_easy_setopt(curl_easy, CURLOPT_HTTPHEADER, curl_headers);
> curl_easy_setopt(curl_easy, CURLOPT_POSTFIELDS, body.c_str());
>
> curl_multi_add_handle(curl, curl_easy);
>
> int still_running = 0;
> do {
> curl_multi_perform(curl, &still_running);
> if (still_running)
> curl_multi_wait(curl, nullptr, 0, 1000, nullptr);
> } while (still_running);
> curl_slist_free_all(curl_headers);
>

When I run my program in valgrind, I see memory errors. What am I doing
wrong?

==60126== Memcheck, a memory error detector
> ==60126== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
> ==60126== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright
> info
> ==60126== Command: ./test
> ==60126==
> ==60126== Conditional jump or move depends on uninitialised value(s)
> ==60126== at 0x53EA551: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53EA8DF: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53F9CDF: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53FA131: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x54305DC: gnutls_x509_trust_list_add_cas (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x543237A: gnutls_x509_trust_list_add_trust_mem (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432811: gnutls_x509_trust_list_add_trust_file (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432AE4: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432B2E: gnutls_x509_trust_list_add_trust_dir (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53B12BD: gnutls_certificate_set_x509_trust_dir (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x49618B4: ??? (in
> /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.6.0)
> ==60126== by 0x4963AEE: ??? (in
> /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4.6.0)
> ==60126==
> ==60126== Conditional jump or move depends on uninitialised value(s)
> ==60126== at 0x53EA551: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53EA8DF: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53F9CDF: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x53FA177: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5424EFA: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x543371D: gnutls_x509_ext_import_subject_alt_names (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5428669: gnutls_x509_crt_import (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5428AF3: gnutls_x509_crt_list_import (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5428DBF: gnutls_x509_crt_list_import2 (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432359: gnutls_x509_trust_list_add_trust_mem (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432811: gnutls_x509_trust_list_add_trust_file (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126== by 0x5432AE4: ??? (in
> /usr/lib/x86_64-linux-gnu/libgnutls.so.30.27.0)
> ==60126==
>
>
>


-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-09-18