cURL / Mailing Lists / curl-library / Single Mail


libcurl crashing on Windows

From: Jo Meder <>
Date: Wed, 28 Feb 2007 15:28:06 +1300


I've just started playing about with libcurl on Windows ( XP at this
stage ). I've built v7.16.1 from the source using the curllib project
included in the distro. I'm using VS 2003 ( VC 7.1 ) so the project
had to be converted. I've made a few changes to the project, I build
libcurl as a static lib and use the multithreaded DLL runtimes. I've
found that the debug build works fine in the debug build of my app,
but I get a consistent crash with the release build. The stack trace
looks like this :

> _heap_alloc(size=2083791242) Line 212 C
          free(pBlock=0x0e750000) Line 103 C
          free(pBlock=0x0e775b90) Line 103 C
          destroy_thread_sync_data(tsd=0x0e775b88) Line 186 C
          gethostbyname_thread(arg=0x00000000) Line 331 C
          _threadstartex(ptd=0x0ebd6e08) Line 241 C

The fact that the arg param for gethostbyname_thread is NULL looks
like it might be the start of the problems, but possibly it's also
being bad data being passed into the thread in the first place.

Here's how I'm calling libcurl ( some irrelevant code trimmed out ) :

        CURL* curl;
        CURLcode res;
        curl = curl_easy_init();
        if ( curl != NULL )
                curl_easy_setopt( curl, CURLOPT_URL, "" );
                curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, CurlWriteFunc );
                res = curl_easy_perform( curl );
                curl_easy_cleanup( curl );

CurlWriteFunc looks like this :

size_t CurlWriteFunc( void* ptr, size_t size, size_t num, void* stream )
        size_t bytesHandled = 0;
        std::cout << "size = " << size << ", num = " << num << std::endl;
        if ( ( size == 1 ) && ( num != 0 ) )
                gBufferStr.append( ( char* )ptr, num );
                bytesHandled = num * size;
        return bytesHandled;

If I comment out the line :

curl_easy_setopt( curl, CURLOPT_URL, "" );

then I don't get a crash, but I assume that's because libcurl doesn't
actually do any host lookup in that case.

I've been using the same code in OS X and it works fine, as well for
debug builds of my app on Windows. A small Windows test app for
libcurl ( essentially the same code as above ) works fine in debug
and release builds.

I've found that if I use the debug build of libcurl in the release
build of my app I get a slightly different crash, but what with the
different runtimes used I don't think anything reliable can be read
into that.

Originally I was running the above code in a boost thread, but
removing the boost threads stuff from my project and just calling the
code directly also causes the crash in release builds.



Jo Meder
Planetside Software
Terragen for Macintosh
Photorealistic landscapes on your Mac
Received on 2007-02-28