cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: calling function twice causes crash

From: Shaun Dawson <scdawson_at_gmail.com>
Date: Thu, 6 Jul 2006 14:38:40 -0500

My guess is that it is because you are calling curl_global_init more than once.

Shaun

On 7/6/06, Sheldon Neuberger <neuberger_at_gmail.com> wrote:
> I have the following function:
>
> char * getip(void)
> {
> CURL *curl_handle;
>
> struct MemoryStruct chunk;
>
> chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
> chunk.size = 0; /* no data at this point */
>
> curl_global_init(CURL_GLOBAL_ALL);
>
> /* init the curl session */
> curl_handle = curl_easy_init();
>
> /* specify URL to get */
> curl_easy_setopt(curl_handle, CURLOPT_URL, "http://this-ip.com/micro/");
>
> /* send all data to this function */
> curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
>
> /* we pass our 'chunk' struct to the callback function */
> curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
>
> /* some servers don't like requests that are made without a user-agent
> field, so we provide one */
> curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
>
> /* get it! */
> curl_easy_perform(curl_handle);
>
> /* cleanup curl stuff */
> curl_easy_cleanup(curl_handle);
>
> return chunk.memory;
> }
>
>
> When I call this function for the second time in my program, it crashes. I
> run curl_easy_cleanup at the end of the function but it still crashes. Why
> is this?
>
Received on 2006-07-06