cURL / Mailing Lists / curl-library / Single Mail

curl-library

glibc-Error

From: Giuliano Montecarlo <gggiuly_at_googlemail.com>
Date: Sat, 12 Nov 2005 23:55:23 +0100

Hi,
If I compile the code on windows with Dev-Cpp, it works, but sometimes not.
I tried now to build it for GNU/Linux, but glibc gives me errors.
Code:
--snip--
char* getSite(char* user, char* pass) {
  struct MemoryStruct {
    char *memory;
    size_t size;
  };

  void *myrealloc(void *ptr, size_t size) {
    if(ptr)
      return realloc(ptr, size);
    else
      return malloc(size);
  }

  size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) {
    size_t realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;
    mem->memory = (char *)myrealloc(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;
  }

  CURL *curl_handle;
  CURLcode res;
  struct MemoryStruct chunk;
  chunk.memory=NULL;
  chunk.size = 0;
  curl_global_init(CURL_GLOBAL_ALL);
  curl_handle = curl_easy_init();
  char* buff = malloc(sizeof(FREEPAYURL)+strlen(user)+strlen(pass)+1);
  sprintf(buff, FREEPAYURL, user, pass);
  curl_easy_setopt(curl_handle, CURLOPT_URL,
"http://ipods.freepay.com/Default.aspx");
  curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, buff);
  curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
  curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "");
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
  curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
  curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
  while(res!=CURLE_OK) {
    res=curl_easy_perform(curl_handle);
  }
  curl_easy_cleanup(curl_handle);
  free(buff);
  return chunk.memory;
}
--snap--
(FREEPAYURL is #DEFINE'd POST-Data)

gdb gives me:
--snip--
(gdb) run
Starting program: /home/giuly/GeePod/Interface/GeePod
*** glibc detected *** free(): invalid next size (fast): 0x000000000058ba80 ***

Program received signal SIGABRT, Aborted.
0x00002aaaac347ad9 in kill () from /lib/libc.so.6
(gdb) bt
#0 0x00002aaaac347ad9 in kill () from /lib/libc.so.6
#1 0x00002aaaac3477cd in raise () from /lib/libc.so.6
#2 0x00002aaaac348b12 in abort () from /lib/libc.so.6
#3 0x00002aaaac37acd7 in __fsetlocking () from /lib/libc.so.6
#4 0x00002aaaac37fba0 in malloc_usable_size () from /lib/libc.so.6
#5 0x00002aaaac38070a in free () from /lib/libc.so.6
#6 0x00002aaaabd676e9 in curl_slist_free_all () from /usr/lib/libcurl.so.3
#7 0x00002aaaabd702b4 in Curl_close () from /usr/lib/libcurl.so.3
#8 0x0000000000401e34 in getSite ()
#9 0x00000000004023e3 in Update ()
#10 0x0000000000402baa in main ()
--snap--

So, does anyone know, whats wrong there?

GAM
Received on 2005-11-13