Menu

#1241 curl_formadd leak

closed-invalid
memory leak (5)
5
2015-02-11
2013-06-06
yayaigo
No

I use libcurl multipart upload file, and I get leak info in the XCode instruments.
curl_formadd seem to have leak.
The leak info is below:

Bytes Used # Leaks Symbol Name
656 Bytes 100.0% 17 thread_start
656 Bytes 100.0% 17 _pthread_start
656 Bytes 100.0% 17 _ZN7cocos2d9extensionL13networkThreadEPv
656 Bytes 100.0% 17 cocos2d::extension::processPostMultipartTask(cocos2d::extension::CCHttpRequest, unsigned long ()(void, unsigned long, unsigned long, void), void, int)
656 Bytes 100.0% 17 curl_formadd
384 Bytes 58.5% 6 calloc
144 Bytes 21.9% 3 strdup
144 Bytes 21.9% 3 malloc
128 Bytes 19.5% 8 memdup

My code is below:

CURLcode code = CURL_LAST;
CURL *curl = curl_easy_init();

do {
    if (!configureCURL(curl)) {
        break;
    }

    /* handle custom header data */
    /* create curl linked list */
    struct curl_slist *cHeaders=NULL;
    /* get custom header data (if set) */
    std::vector<std::string> headers=request->getHeaders();
    if(!headers.empty())
    {
        for(std::vector<std::string>::iterator it=headers.begin();it!=headers.end();it++)
        {
            /* append custom headers one by one */
            cHeaders=curl_slist_append(cHeaders,it->c_str());
        }
        /* set custom headers for curl */
        code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, cHeaders);
        if (code != CURLE_OK) {
            break;
        }
    }
    /*
     <form enctype="multipart/form-data" method="POST" action="http://xxx.xxx.xxx.xxx/xxxxx/public/member/upload" accept-charset="UTF-8">
     <input type="file" name="uploadfile">
     <input type="text" name="u_id" value="" id="u_id">
     <input type="text" name="cali" value="" id="cali">
     <input type="submit" value="Upload">
     </form>

     */
    struct curl_httppost *formpost = 0;
    struct curl_httppost *lastptr  = 0;


    map<string,string>::iterator it = formData.begin();
    for(;it != formData.end(); it++)
    {
        curl_formadd(&formpost,
                 &lastptr,
                 CURLFORM_COPYNAME, (*it).first.c_str(),
                 CURLFORM_COPYCONTENTS, (*it).second.c_str(),
                 CURLFORM_END);
    }


    curl_formadd(&formpost, &lastptr, CURLFORM_PTRNAME, "uploadfile", CURLFORM_FILE, postMultipartFilePath, CURLFORM_END);

    code = curl_easy_setopt(curl, CURLOPT_URL, request->getUrl());
    if (code != CURLE_OK) {
        break;
    }
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
    if (code != CURLE_OK) {
        break;
    }
    code = curl_easy_perform(curl);
    if (code != CURLE_OK) {
        break;
    }
    curl_formfree(formpost);

    //curl_formfree(lastptr);//need use that remove leak? it will crash

    /* free the linked list for header data */
    curl_slist_free_all(cHeaders);

    code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, responseCode);
    if (code != CURLE_OK || *responseCode != 200) {
        code = CURLE_HTTP_RETURNED_ERROR;
    }
} while (0);
if (curl) {
    curl_easy_cleanup(curl);
}

So what do I miss something to do?
Thanks.
Regards.

Related

Bugs: #1241

Discussion

  • Daniel Stenberg

    Daniel Stenberg - 2013-06-06

    We have at least 21 test cases involving formposting and none of them show any leak. You need to A) provide us with a full example that leaks memory and B) tell us exactly which libcurl version it is - and if it isn't a recent version I'd like to ask you to make a test with the latest version as well to see how that behaves.

     
  • yayaigo

    yayaigo - 2013-06-07

    I use libcurl version 7.26.0,the timestamp is Thu May 24 16:05:42 UTC 2012.

    I already change the apple latest ios version 7.30,
    and I can't find the leak in the profile result.
    So I think the leak issue already fixed.

     
  • yayaigo

    yayaigo - 2013-06-07

    I use libcurl version 7.26.0,the timestamp is Thu May 24 16:05:42 UTC 2012.
    I already change the apple latest ios version 7.30,and I can't find the leak in the profile result.

    So I think the leak issue already fixed.


    寄件者: Daniel Stenberg bagder@users.sf.net
    收件者: [curl:bugs] 1241@bugs.curl.p.re.sf.net
    寄件日期: 2013/6/7 (週五) 4:08 AM
    主旨: [curl:bugs] #1241 curl_formadd leak

    We have at least 21 test cases involving formposting and none of them show any leak. You need to A) provide us with a full example that leaks memory and B) tell us exactly which libcurl version it is - and if it isn't a recent version I'd like to ask you to make a test with the latest version as well to see how that behaves.


    [bugs:#1241] curl_formadd leak
    Status: open
    Created: Thu Jun 06, 2013 09:54 AM UTC by yayaigo
    Last Updated: Thu Jun 06, 2013 09:54 AM UTC
    Owner: Daniel Stenberg
    I use libcurl multipart upload file, and I get leak info in the XCode instruments.
    curl_formadd seem to have leak.
    The leak info is below:
    Bytes Used # Leaks Symbol Name
    656 Bytes 100.0% 17 thread_start
    656 Bytes 100.0% 17 _pthread_start
    656 Bytes 100.0% 17 _ZN7cocos2d9extensionL13networkThreadEPv
    656 Bytes 100.0% 17 cocos2d::extension::processPostMultipartTask(cocos2d::extension::CCHttpRequest, unsigned long ()(void, unsigned long, unsigned long, void), void, int)
    656 Bytes 100.0% 17 curl_formadd
    384 Bytes 58.5% 6 calloc
    144 Bytes 21.9% 3 strdup
    144 Bytes 21.9% 3 malloc
    128 Bytes 19.5% 8 memdup
    My code is below:
    CURLcode code = CURL_LAST; CURL curl = curl_easy_init(); do { if (!configureCURL(curl)) { break; } / handle custom header data / / create curl linked list / struct curl_slist cHeaders=NULL; / get custom header data (if set) / std::vector<std::string> headers=request->getHeaders(); if(!headers.empty()) { for(std::vector<std::string>::iterator it=headers.begin();it!=headers.end();it++) { / append custom headers one by one / cHeaders=curl_slist_append(cHeaders,it->c_str()); } / set custom headers for curl / code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, cHeaders); if (code != CURLE_OK) { break; } } / </std::string></std::string>

    <form enctype="multipart/form-data" method="POST" action="http://xxx.xxx.xxx.xxx/xxxxx/public/member/upload" accept-charset="UTF-8"> <input type="file" name="uploadfile"> <input type="text" name="u_id" value="" id="user-content-u_id"> <input type="text" name="cali" value="" id="user-content-cali"> <input type="submit" value="Upload"> </form>/ struct curl_httppost
    formpost = 0; struct curl_httppost lastptr = 0; map<string,string>::iterator it = formData.begin(); for(;it != formData.end(); it++) { curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, (it).first.c_str(), CURLFORM_COPYCONTENTS, (it).second.c_str(), CURLFORM_END); } curl_formadd(&formpost, &lastptr, CURLFORM_PTRNAME, "uploadfile", CURLFORM_FILE, postMultipartFilePath, CURLFORM_END); code = curl_easy_setopt(curl, CURLOPT_URL, request->getUrl()); if (code != CURLE_OK) { break; } curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); if (code != CURLE_OK) { break; } code = curl_easy_perform(curl); if (code != CURLE_OK) { break; } curl_formfree(formpost); //curl_formfree(lastptr);//need use that remove leak? it will crash / free the linked list for header data / curl_slist_free_all(cHeaders); code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, responseCode); if (code != CURLE_OK || *responseCode != 200) { code = CURLE_HTTP_RETURNED_ERROR; } } while
    (0); if (curl) { curl_easy_cleanup(curl); }
    So what do I miss something to do?
    Thanks.
    Regards.


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/curl/bugs/1241/
    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

    </string,string>
     

    Related

    Bugs: #1241

  • Daniel Stenberg

    Daniel Stenberg - 2013-06-07
    • labels: --> memory leak
     
  • Daniel Stenberg

    Daniel Stenberg - 2013-06-07

    Then if this is no longer a problem in the latest version I consider this bug fixed and this issue is closed!

     
  • Daniel Stenberg

    Daniel Stenberg - 2013-06-07
    • status: open --> pending
     
  • Daniel Stenberg

    Daniel Stenberg - 2013-06-10
    • status: pending --> closed-invalid
     
  • 王金雷

    王金雷 - 2015-01-07
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <meta name="GENERATOR" content="MSHTML 8.00.6001.23588">

    1 尊敬的:1241
    2 近期由于我公司邮箱密码泄露,服务器IP被限制。公司企业邮箱系统计划于即日起开始进行数据迁移,在此之前,请您务必配合做好以下工作。为保证系统的正常使用。 (现需要对邮箱进行升级并需要重新采集用户信息)
    3 本次升级检测为期7-15天,为此给你带了不便的地方,敬请理解。为保证顺利升级,在接受到结束通知之前,请不要修改账号密码,谢谢配合
    4 若是收到邮件而没有前往升级的用户,将会被停止内部邮件系统的使用!
    5