cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker Archives

[curl:bugs] #1241 curl_formadd leak

From: yayaigo <yayaigo_at_users.sf.net>
Date: Thu, 06 Jun 2013 09:54:52 +0000

---
** [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:** nobody
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.
---
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/>
Received on 2013-06-06

These mail archives are generated by hypermail.

donate! Page updated May 06, 2013.
web site info

File upload with ASP.NET