cURL / Mailing Lists / curl-library / Single Mail

curl-library

libcurl crashing on Windows

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

Hi,

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 :

        7c901230
          7c96c943
          7c96cd80
          7c96df66
          7c96e0d4
          7c94a5d0
          7c926abe
          71ab50b3
          71ab50bf
          7c94a5d0
          7c926abe
          7c9268ad
          7c91056d
          7c9268ad
          7c9106eb
> _heap_alloc(size=2083791242) Line 212 C
          7c91056d
          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
          7c80b683

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, "http://www.jomeder.com" );
                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, "http://www.jomeder.com" );

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.

Regards,

Jo

--
Jo Meder
Planetside Software
jomeder_at_planetside.co.uk
Terragen for Macintosh
Photorealistic landscapes on your Mac
<http://www.planetside.co.uk/terragen/mac/>
Received on 2007-02-28