curl-library
Re: crash in libcurl
Date: Mon, 24 Oct 2005 16:41:19 -0700 (PDT)
Hi, I couldn't post the whole thing. But here's the
main function. There's a pthread looping to call this
function every minute. I initialized ssl callback,
message queue, timers etc in there before starting the
loop. I also use libexpat to parse the xml doc.
Note that if I take out curl_easy_clean, it would
still crash in curl_easy_perform, in same __libc_free.
>From the stack, I noticed that the argument pointer
passed to __libc_free was not the same pointer for
some reason. That's why I was thinking I may have
linked the wrong libraries.
static MUTEX_TYPE *mutex_buf= NULL;
CURL *curlHandle = NULL;
struct curl_slist *contentHeaders = NULL;
char xmlHeaderBuf[128];
char userAccount[64];
XML_Parser xmlParser = NULL;
size_t
curlEasyCb(void *ptr, size_t size, size_t nmemb, void
*data)
{
size_t realsize = size * nmemb;
char *buf = data;
/* FIXME copy max 1024 bytes per run */
memcpy(buf, ptr, realsize);
buf[realsize] = 0;
xmlParse(buf, 1);
return realsize;
}
int
querySend()
{
CURLcode res;
if (curlHandle == NULL) {
/* init the curl session */
if ((curlHandle = curl_easy_init()) == NULL) {
return -1;
}
curl_easy_setopt(curlHandle, CURLOPT_URL,
"https://my-url");
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYPEER,
0);
curl_easy_setopt(curlHandle, CURLOPT_SSL_VERIFYHOST,
0);
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION,
curlEasyCb);
sprintf(userAccount, "test:test123");
curl_easy_setopt(curlHandle, CURLOPT_USERPWD,
userAccount);
sprintf(xmlHeaderBuf, "<?xml version=\"1.0\"
encoding=\"UTF-8\" standalone=\"yes\"?><request
xmlns=\"http://my-url/idiom\" />\0");
/* post binary data */
contentHeaders = curl_slist_append(contentHeaders,
"Content-Type: text/xml");
curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS,
xmlHeaderBuf);
curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDSIZE,
strlen(xmlHeaderBuf));
curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER,
contentHeaders);
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA,
(void *)respBuf);
}
res = curl_easy_perform(curlHandle);
#if 1
curl_easy_cleanup(curlHandle);
curlHandle = NULL;
curl_slist_free_all(contentHeaders);
curl = contentHeaders = NULL;
#endif
return 0;
}
--- Jason Pump <jpump_at_mindspring.com> wrote:
> Hi, can you post your code? If you call
> curl_easy_cleanup() to have to
> call curl_easy_init() before using the pointer
> again. Reading between
> the lines it kind of appears that might be your
> problem. I have what you
> describe on many platforms with no problems, once I
> can get it to compile.
>
> J D wrote:
>
> >Thanks for the tip. I'll continue to look. But the
> >pthread I have is pretty simple. All it does is to
> >query a server every 5 minutes using a piece of
> code
> >very similar to the https.c sample. This crash
> usually
> >happens when second query is sent. And it crashes
> in
> >curl_easy_perform if I keep same curl handle.
> >
> >The version of libcurl is 7.14.1.
> >
> >-Justin
> >
> >--- Daniel Stenberg <daniel_at_haxx.se> wrote:
> >
> >
> >
> >>On Fri, 21 Oct 2005, J D wrote:
> >>
> >>
> >>
> >>>I need a quick https client but it crashes every
> >>>
> >>>
> >>time I call
> >>
> >>
> >>>cury_easy_cleanup. It looks like a bad pointer
> >>>
> >>>
> >>being freed.
> >>
> >>The most common reason for crashes like this is
> that
> >>your application has
> >>destroyed some memory.
> >>
> >>
> >>
> >>>But I suspect I did something wrong while
> >>>
> >>>
> >>cross-compling libcurl.
> >>
> >>I don't think that is very likely. If you could
> >>build and run libcurl, it is
> >>almost guaranteed that you built it right.
> >>
> >>--
> >> Commercial curl and libcurl Technical Support:
> >>http://haxx.se/curl.html
> >>
> >>
> >>
> >
> >
> >
> >
>
>
Received on 2005-10-25