cURL / Mailing Lists / curl-library / Single Mail

curl-library

Invalid Address specified to RtlValidateHeap in curl_slist_free_all

From: Huzaifa Al Nahas <halnahas_at_gmail.com>
Date: Tue, 9 Dec 2008 19:16:00 -0800

The function curl_slist_free_all is crashing when it tries to free
memory. I first suspected that this is due to conflicting runtime
libraries. However I verified that both libcurl and my program are
compiled using MDd (Mutithreaded Debug dll). What else could cause
this problem?

The code that I used is:

        char *header;
        CURL *curl;
        CURLcode res;
        struct curl_slist* headers=NULL;
        string data = "xyz";
        struct WriteThis pooh;
        pooh.readptr = data.c_str();
        pooh.sizeleft = strlen(data.c_str());

        curl = curl_easy_init();
        char errorBuffer[CURL_ERROR_SIZE];

if(curl) {
                curl_easy_setopt(curl, CURLOPT_URL, newhost.c_str());
                curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &errorBuffer);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_connection_msg);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);

                curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, process_connection_header);
                curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &header);

                headers = curl_slist_append(headers, "Content-Type: text/xml");
                /* pass our list of custom made headers */
                curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

                curl_easy_setopt(curl, CURLOPT_POST, 1L);

                curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);

                curl_easy_setopt(curl, CURLOPT_READDATA, &pooh);

                curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (curl_off_t)pooh.sizeleft);

                // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

                res = curl_easy_perform(curl);

                .......................................

                curl_slist_free_all(headers);
                curl_easy_cleanup(curl);
}

and it crashes at curl_slist_free_all(headers). Below is the error
message and call stack.

Invalid Address specified to RtlValidateHeap( 003B0000, 003C3128 )
Windows has triggered a breakpoint in xyz.exe.

         ntdll.dll!7c901230()
         [Frames below may be incorrect and/or missing, no symbols loaded for
ntdll.dll]
         ntdll.dll!7c96c943()
         ntdll.dll!7c96cd80()
         ntdll.dll!7c960af8()
         kernel32.dll!7c85e9cf()
> msvcr80d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x003c3148) Line 1963 C++
         msvcr80d.dll!_free_dbg_nolock(void * pUserData=0x003c3148, int
nBlockUse=1) Line 1252 + 0x9 bytes C++
         msvcr80d.dll!_free_dbg(void * pUserData=0x003c3148, int nBlockUse=1)
 Line 1194 + 0xd bytes C++
         msvcr80d.dll!free(void * pUserData=0x003c3148) Line 1152 + 0xb bytes C++
         xyz.exe!curl_slist_free_all(curl_slist * list=0x003b6010) Line 133
+ 0xe bytes C
         xyz.exe!connect(std::basic_string<char,std::char_traits<char>,std::allocator<char>
> host="https://xxx/xxx/xxx",
std::basic_string<char,std::char_traits<char>,std::allocator<char> >
username="xxx",
std::basic_string<char,std::char_traits<char>,std::allocator<char> >
password="xxx") Line 529 + 0x9 bytes C++
         xyz.exe!main(int argc=7, char * * argv=0x003b5db8) Line 1476 + 0xa9 bytes C++
         xyz.exe!__tmainCRTStartup() Line 586 + 0x19 bytes C
         xyz.exe!mainCRTStartup() Line 403 C
         kernel32.dll!7c816fd7()
Received on 2008-12-10