curl-library
RE: curl crash
Date: Thu, 21 Mar 2002 17:24:17 -0800
I'm quite sure that a memset(&chunk,0,sizeof chunk); before
res = curl_easy_perform(curl); /* CRASH HERE
would help you.
I'm sure now you know why :)
Miklos
> -----Original Message-----
> From: curl-library-admin_at_lists.sourceforge.net
> [mailto:curl-library-admin_at_lists.sourceforge.net]On Behalf Of Anurag
> Singh
> Sent: Thursday, March 21, 2002 5:02 PM
> To: curl-library_at_lists.sourceforge.net
> Subject: curl crash
>
>
> Hi,
>
> My C program on SCO Unix crashed during calling the
> curl_easy_perform() with saving the file in the
> memory. It happened randomly and usually after a
> couple of successful calls.
>
> Im wondering if I set the options correctly for the
> curl handle. Your assistance is appreciated.
>
> Here is my codes.
>
> /*****************************/
> size_t
> WriteMemoryCallback(void *ptr, size_t size, size_t
> nmemb, void *data)
> {
> register int realsize = size * nmemb;
> struct MemoryStruct *mem = (struct MemoryStruct
> *)data;
>
> mem->memory = (char *)realloc(mem->memory, mem->size
> + realsize + 1);
> if (mem->memory) {
> memcpy(&(mem->memory[mem->size]), ptr, realsize);
> mem->size += realsize;
> mem->memory[mem->size] = 0;
> }
> return realsize;
> }
>
> PostToURL(char *URLString, char *Input, char *Results,
> int ConntTimeOut, int TimeOut)
> {
> CURL *curl;
> CURLcode res;
> struct MemoryStruct chunk;
>
> chunk.memory=NULL;
> chunk.size = 0
> curl = curl_easy_init();
>
>
> if(curl)
> {
> curl_easy_setopt(curl, CURLOPT_URL,
> URLString);
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
> WriteMemoryCallback);
> curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
> Input);
> curl_easy_setopt(curl, CURLOPT_FILE, (void
> *)&chunk);
>
> curl_easy_setopt(curl, CURLOPT_TIMEOUT,
> TimeOut);
> curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT,
> ConntTimeOut);
> res = curl_easy_perform(curl); /* CRASH HERE
> */
> if ( res != CURLE_OK )
> {
> curl_easy_cleanup(curl);
> if (chunk.memory != NULL)
> free(chunk.memory);
> return 1;
> }
> else
> {
> memcpy(Results, chunk.memory, chunk.size);
> curl_easy_cleanup(curl);
> if (chunk.memory != NULL)
> free(chunk.memory);
> return 0;
> }
>
> }
> curl_easy_cleanup(curl);
> if (chunk.memory != NULL)
> free(chunk.memory);
> return 1;
> }
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Movies - coverage of the 74th Academy Awards.
> http://movies.yahoo.com/
>
Received on 2002-03-22