cURL / Mailing Lists / curl-library / Single Mail

curl-library

segmentation fault happened in Curl_getconnectinfo()

From: leodliu <leodliu_at_126.com>
Date: Wed, 14 Apr 2010 21:56:16 +0800 (CST)

segmentation fault happened in Curl_getconnectinfo()

the core info is:

#0 0x00000000004a3ff8 in Curl_getconnectinfo ()
    at /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
#1 0x00000000004b76c2 in Curl_connect ()
    at /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
#2 0x00000000004a581b in multi_runsingle ()
    at /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
#3 0x00000000004a61fc in curl_multi_perform ()
    at /usr/lib/gcc/x86_64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/bits/locale_facets.tcc:2443
#4 0x000000000042b976 in Process (this=0x7fbffff5c0)
    at mycurlcode.cpp:543

The version of curl is 7.20.0, c-ares is 1.7.1

I must use multi perform, beacuse there is a lot of web page to get. But the segmentation fault make me lost my head.I don't know how to solve it , please help me. Thanks you!!

part code is :

///////////////////easy option

curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, 25000);

    // low speed limit and time
    curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 100);
    curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 5);
     
    // CONNECT TIMEOUT
    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 5000);
    
    //WriteCallback
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)(task.get()));
    
    //DNS
    curl_easy_setopt(curl, CURLOPT_DNS_USE_GLOBAL_CACHE, 1);
    curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 3600);

    
    //VERBOSE
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 0);
    
        
    //HTTPHEADER
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, mHdr);
    
    //HEAD FUNCTION
    curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, HeadCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)(task.get()));
        

/////////////Process
int Process()
{
    int running = 0;
    fd_set fdr;
    fd_set fdw;
    fd_set fde;
    int fdNum = 0;
    struct timeval timeout;
    CURLMsg *msg = NULL;
    int msgsLeft = 0;
    std::map<CURL*, std::tr1::shared_ptr<Task> >::iterator pIter;
    //start down
    while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(mCurlm, &running))
    {
        ;//VOID
    }
    //run
    FD_ZERO(&fdr);
    FD_ZERO(&fdw);
    FD_ZERO(&fde);
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    int ret;
    running = 0;
    curl_multi_fdset(mCurlm, &fdr, &fdw, &fde, &fdNum);
    if (fdNum < 0)
    {
        return 0;
    }
    else
    {
        if ((ret = select(fdNum + 1, &fdr, &fdw, &fde, &timeout)) > 0)
        {
            while (curl_multi_perform(mCurlm, &running) == CURLM_CALL_MULTI_PERFORM)
            {
                ;//VOID
            }
        }
        else if (ret < 0)
        {
            return -1;
            //select fault
        }
    }
    //Get result after dwon
    while (( msg = curl_multi_info_read(mCurlm, &msgsLeft)))
    {
        if (msg->msg != CURLMSG_DONE)
        {
            continue;
        }
        CURL* curl = msg->easy_handle;
        pIter = mTasks.find(curl);
        if (pIter != mTasks.end())
        {
            Judge(pIter, msg->data.result);
        }
    }
    return 1;
}
 
 
 
///////////HeadCallback
size_t HeadCallback(void *ptr, size_t size, size_t nmemb, void *data)
{
    Task* ta = (Task*)data;
    size_t realsize = size * nmemb;
    char* buf = (char*) ptr;
    if (memcmp(buf, "Content-Length", strlen("Content-Length")) == 0)
    {
        sscanf(buf, "Content-Length%*[: ]%ld", &(ta->result.size));
    }
    else if (memcmp(buf, "213", strlen("213")) == 0)
    {
        sscanf(buf, "213%*[: ]%ld", &(ta->result.size));
    }
    return realsize;
}

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-04-14