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.

curl_easy_perform() crash?

From: Daniel Polski via curl-library <curl-library_at_cool.haxx.se>
Date: Tue, 27 Aug 2019 13:49:25 +0200

Hello,
I'm trying to figure out why my application crash sometimes, and ended
up with the following stack:

Thread #19 [backend_ser] 14800 [core: 3] (Suspended : Signal :
SIGABRT:Aborted)
__GI_raise() at raise.c:50 0x7ffff783ced7
__GI_abort() at abort.c:79 0x7ffff781e535
__libc_message() at libc_fatal.c:181 0x7ffff7885726
malloc_printerr() at malloc.c:5,352 0x7ffff788c59a
unlink_chunk() at malloc.c:1,464 0x7ffff788c841
_int_malloc() at malloc.c:4,049 0x7ffff7890534
__GI___libc_malloc() at malloc.c:3,073 0x7ffff7891caa
0x7ffff7cdc078
0x7ffff7ced121
0x7ffff7cede3c
0x7ffff7cee2b1
0x7ffff7cee549
0x7ffff7cedbf2
0x7ffff7cee2b1
0x7ffff7cee549
0x7ffff7cedbf2
0x7ffff7cee2b1
0x7ffff7cee549
0x7ffff7cedbf2
ASN1_item_ex_d2i() at 0x7ffff7cee64d
ASN1_item_d2i() at 0x7ffff7cee6cb
PEM_X509_INFO_read_bio() at 0x7ffff7ddb29c
X509_load_cert_crl_file() at 0x7ffff7e3a54c
0x7ffff7e3a6aa
X509_STORE_load_locations() at 0x7ffff7e3d33f
ossl_connect_step1() at openssl.c:2,615 0x55555565d6a4
ossl_connect_common() at openssl.c:3,571 0x5555556608e5
Curl_ossl_connect_nonblocking() at openssl.c:3,657 0x555555660b61
Curl_ssl_connect_nonblocking() at vtls.c:275 0x555555612cb5
https_connecting() at http.c:1,574 0x55555561e548
Curl_http_connect() at http.c:1,496 0x55555561e32a
Curl_protocol_connect() at url.c:1,549 0x55555562878e
multi_runsingle() at multi.c:1,556 0x5555555f76d6
curl_multi_perform() at multi.c:2,104 0x5555555f8948
easy_transfer() at easy.c:595 0x5555555efe79
easy_perform() at easy.c:688 0x5555555f00f8
curl_easy_perform() at easy.c:707 0x5555555f015f
nordnetApi::query() at nordnetApi.cpp:250 0x5555555b8009
nordnetApi::newsItem() at nordnetApi.cpp:1,247 0x5555555bee03
feedProcessor::run() at feedProcessor.cpp:1,380 0x5555555ac786
<...more frames...>

The debug output in eclipse-cdt states "corrupted size vs. prev_size".

The function leading to the curl_easy_perform(..) call looks like this:

---------------
bool nordnetApi::query(
     std::string url, std::string method,
     std::string data, Document &d, bool is_login_call, bool log_call,
bool log_response, bool parse_numbers_as_strings)
{

     int retry_counter = 0;

     while(1){

         //wait for valid login, if it isn't the login call itself
         if(!is_login_call){
             if(!block_until_logged_in()){
                 //block_until_logged_in returns false if shutdown is
pending
                 return false;
             }
         }

         std::string murl = this->apiUrl + url;
         std::string s = "";

         CURLcode res;
         CURL *curl = curl_easy_init();

     #ifdef DEBUG_CURL
         curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debug_callback);
         curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
     #endif

         if (!curl) {
             FILE_LOG(logERROR)<<"Error starting curl";
             return false;
         }

         struct curl_slist *header = NULL;
         header = curl_slist_append(header, "Accept-Language: sv");
         header = curl_slist_append(header, "Accept: application/json");

         //If we are authenticated, use our credentials
         if(this->sessionKey != "")
         {
             curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
             curl_easy_setopt(curl, CURLOPT_USERNAME,
this->sessionKey.c_str());
             curl_easy_setopt(curl, CURLOPT_PASSWORD,
this->sessionKey.c_str());
         }

         if(log_call){
             FILE_LOG(logINFO)<<murl<<" - data: " << data;
         }
         curl_easy_setopt(curl, CURLOPT_URL, murl.c_str());

         //POST JSON data to the server
         if(method == "POST")
         {
             curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
             curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
         }
         else if(method == "POST-JSON")
         {
             header = curl_slist_append(header, "Content-Type:
application/json");
             curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
             curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
         }
         else if(method == "GET")
         {
             //Just don"t set post data
         }
         else if(method == "DELETE"){
             curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
         }else if(method == "PUT"){
             curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
             header = curl_slist_append(header, "Content-Type:
application/json");
             curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
             curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
         }

         curl_easy_setopt(curl, CURLOPT_HTTPHEADER,         header);
         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
this->CurlWrite_CallbackFunc_StdString);
         curl_easy_setopt(curl, CURLOPT_WRITEDATA,         &s);
         curl_easy_setopt(curl, CURLOPT_SHARE,             sslShare);

         res = curl_easy_perform(curl);

---------------

Any suggestions why curl_easy_perform() sometimes crash? (every day, but
with thousands of calls with no crash).
Or any suggestions how to debug the problem further to find the root
cause (maybe not curl itself, but something it relies on?)

(I've tested curl 7.64 and 7.66-DEV)

Thanks,
Daniel

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-08-27