cURL / Mailing Lists / curl-library / Single Mail

curl-library

curl crash

From: Anurag Singh <splweb_at_yahoo.com>
Date: Thu, 21 Mar 2002 17:02:18 -0800 (PST)

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.

I’m 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