cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Crash when using libcurl as part of a project - Visual Studio 2005

From: Cristi <eblis102_at_yahoo.com>
Date: Tue, 30 Oct 2007 07:56:38 -0700 (PDT)

> > I'm using the source code for libcurl itself in the project, i am
> not using
> > libcurl as a dyanamic library.
>
> I would recommend that you instead build a lib (static or DLL) and
> use that,
> since it'll make it easier for you to upgrade to newer libcurls in
> the future.

I have libcurl in it's own folder, i can just copy-paste the new source
code in there and everything should compile.

> > But if i use the same dll but compiled in Release mode i get a
> crash in
> > curl_easy_perform(). I've traced through the call stack a bit and
> i've
> > noticed that the line it fails in is from hash.c, line no 99: h =
> (struct
> > curl_hash *) malloc(sizeof(struct curl_hash));
> >
> > The callstack also shows malloc.c above hash.c and the error is
> invalid
> > access to memory location, 0x00000000.
>
> I would say that this is due to you mixing memory "models" between
> various
> components in your application, or that something outside of libcurl
> is
> destroying memory somewhere at some point.

The weird thing is that if I compile the plugin in Debug mode (either
dynamically or statically linking it to the MSVC runtime) it works just
fine.

> Other than so, I would recommend using some kind of memory
> tracking/supervising tool (purify, valgrind or similar) to figure
> this out.
>
> > it seems as though there's something wrong with the memory
> functions
> > that curl knows about.
> >
> > If I compile the curlib project with the most verbose warning
> setting
> > turned on I get the following warning:
> > .\easy.c(205) : warning C4232: nonstandard extension used :
> > 'Curl_cmalloc' : address of dllimport 'malloc' is not static,
> identity
> > not guaranteed
> > d:\usr\Microsoft Visual Studio 8\VC\include\stdlib.h(594) :
> see
> > declaration of 'malloc'
>
> What version is this? I can't see any malloc on line 205 in easy.c in
> any
> recent version...
>
> And anyway, this is not a problem with libcurl as I see it. It is
> some kind of
> restriction malloc that VS seems to impose. I honestly don't
> understand the
> warning!

I may have added a few blank lines and messed up the line numbers.
These lines in easy.c (version 7.17.0):

/*
 * If a memory-using function (like curl_getenv) is used before
 * curl_global_init() is called, we need to have these pointers set
already.
 */

curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
curl_free_callback Curl_cfree = (curl_free_callback)free;
curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
curl_strdup_callback Curl_cstrdup =
(curl_strdup_callback)system_strdup;
curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Received on 2007-10-30