curl-library
Re: static link libcurl with VS2010 causes crash
Date: Sat, 12 May 2012 16:16:30 -0700
Hi,
Sorry to resurrect such an old e-mail, but unfortunately I am still
stuck on this problem and I was hoping someone would be willing to
offer advice on how to go about fixing it.
I am performing an HTTPS POST using curl_easy_perform. Every so
often, after calling curl_easy_cleanup, I am getting a crash in the
function below.
/*
* destroy_async_data() cleans up async resolver data and thread handle.
*/
static void destroy_async_data (struct Curl_async *async)
{
if(async->hostname)
free(async->hostname); <<< HERE <<<<<
if(async->os_specific) {
struct thread_data *td = (struct thread_data*) async->os_specific;
if(td->thread_hnd != curl_thread_t_null)
Curl_thread_join(&td->thread_hnd);
destroy_thread_sync_data(&td->tsd);
free(async->os_specific);
}
async->hostname = NULL;
async->os_specific = NULL;
}
I am pretty sure it is not a double-free problem since it looks like
async->hostname is set to NULL afterwards. I also triple-checked that
OpenSSL, Libcurl and my project are all built using the same runtimes
(/MD for release, /MDd for debug). Once it crashes there, I try to
check if the memory is valid, and the debugger shows that the memory
page is valid.
I also tried to rebuild both the latest OpenSSL (1.0.1c) and libcurl
(7.25.0) and still the same problem.
Since this code looks like it is related to the threaded resolver, I
am thinking of building libcurl without threads so that it uses a
single-threaded resolver i.e USE_THREADS_WIN32 set to 0. However,
before I do, I was hoping to verify that this would fix my problem.
Also, besides getting the added benefit of performance via
parallelism, are there any other benefits to using the threaded
resolver?
Thanks,
J
On Thu, Mar 1, 2012 at 2:01 PM, JonathonS <thejunkjon_at_gmail.com> wrote:
> I am still stuck on this :( It looks like I am building libcurl
> correctly, yet it still crashes.
>
> Would anyone know where I can get a pre-built libcurl (and openssl)
> static library for VS2010 of 7.24.0?
>
> I checked the pre-built binaries for the libcurl on the curl page, and
> they are outdated for MSVC and I am not sure if theya re using MSVC
> 2010.
>
> Thanks,
> J
>
>
> On Wed, Feb 22, 2012 at 5:20 PM, JonathonS <thejunkjon_at_gmail.com> wrote:
>> Thanks guys for the help. I tried linking statically as described
>> below and it did produce a static library; however, it is still
>> crashing. It is crashing here in asyn-thread.c when it is trying to
>> free the hostname.
>>
>> /*
>> * destroy_async_data() cleans up async resolver data and thread handle.
>> */
>> static void destroy_async_data (struct Curl_async *async)
>> {
>> if(async->hostname)
>> free(async->hostname); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>
>> if(async->os_specific) {
>> struct thread_data *td = (struct thread_data*) async->os_specific;
>>
>> if(td->thread_hnd != curl_thread_t_null)
>> Curl_thread_join(&td->thread_hnd);
>>
>> destroy_thread_sync_data(&td->tsd);
>>
>> free(async->os_specific);
>> }
>> async->hostname = NULL;
>> async->os_specific = NULL;
>> }
>>
>>
>> Here is how I set the hostname (URL) in my code
>>
>> curlStatus = curl_easy_setopt(m_hCurl, CURLOPT_URL, szURL)
>>
>> where szURL is a local char* variable.
>>
>> any help would be greatly appreciated :) I've been stuck on this thing
>> for 2 weeks now.
>>
>> Thanks,
>> J
>>
>>
>> On Tue, Feb 21, 2012 at 10:27 AM, Ward Willats <libcurl_at_wardco.com> wrote:
>>> At 8:31 AM -0800 2/21/12, JonathonS wrote:
>>>>
>>>> Note that I built libcurl myself and linked dynamically, and
>>>> everything worked fine. So, this must be something specifically to
>>>> static linking.
>>>
>>>
>>> Think this free() problem is probably pilot error.
>>>
>>> I built and linked libcurl 7.32.1 and SLL statically about 2 months ago
>>> under Win7. Been using the output binaries from that since to HTTP POST and
>>> GET with the easy interface and works fine. Had to use the nmake makefiles,
>>> and had to patch them.
>>>
>>> In MakefileBuild.vc on line 104:
>>>
>>> SSL=dll
>>>
>>> should be:
>>>
>>> SSL=static
>>>
>>> ...I think Daniel fixed this. Also I had to change:
>>>
>>> winbuild/MakefileBuild.vc line 102 from:
>>>
>>> SSL_LIBS = libeay32.lib ssleay32.lib
>>>
>>> to:
>>>
>>> SSL_LIBS = libeay32.lib ssleay32.lib gdi32.lib user32.lib advapi32.lib
>>>
>>> ...for OpenSSL 1.0.0e linkage.
>>>
>>> My namke line (YMMV):
>>>
>>> nmake -f Makefile.vc MODE=static VC=10 WITH_SSL=static DEBUG=yes
>>> WITH_DEVEL=../../deps USE_SSPI=no USE_IDN=no clean
>>>
>>> I also have this cryptic note: "Need CURL_STATICLIB in cflags"
>>>
>>> -- Ward
>>>
>>> -------------------------------------------------------------------
>>> List admin: http://cool.haxx.se/list/listinfo/curl-library
>>> Etiquette: http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-05-13