cURL / Mailing Lists / curl-users / Single Mail

curl-users

RE: Memory leak in curl

From: Mick Wall <mick_at_mickandwendy.com>
Date: Fri, 20 Aug 2004 11:53:54 +0100

If are allocating it with a new() would a delete() not be used to free it?

What is m_strReply is it a string or a string *

I use the one from the example without problems, as follows

struct MemoryStruct {
  char *memory;
  size_t size;
};

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;
}

and in the main program...

int main(int argc, char **argv)
{
  CURL *curl;
  CURLcode res;
  struct MemoryStruct chunk;

  chunk.memory=NULL; /* we expect realloc(NULL, size) to work */
  chunk.size = 0; /* no data at this point */

...

   /* send all data to this function */
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

   /* we pass our 'chunk' struct to the callback function */
   curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

...
}

Mick
-----Original Message-----
From: curl-users-bounces_at_cool.haxx.se on behalf of Rupesh
Sent: Fri 20/08/2004 11:23
To: curl-users_at_cool.haxx.se
Cc:
Subject: Memory leak in curl
Hi,
I am using curl library version 7.10.5 for HTTP1.1
client functionality. I am receiving data received
from server in callback function. After I receive the
data I am trying to free it using curl_free fuction
but it gives me core dump. If I don't delete it I am
getting memory leak for that data.

This is the code for call back function which I have
written.

size_t ReadReply(void *buffer, size_t size, size_t
nmemb, void *userp)
{
    m_strReply = new char[size*nmemb +1 ];
    memset(m_strReply,0,size*nmemb);
    memcpy(m_strReply,buffer,size*nmemb);
    return size*nmemb;
}
How can I delete memory allocated for first parameter
in this function or curl do it for me?

I tried free_curl(buffer) it is giving me core dump.

Thanks in advance

Rupesh

  

________________________________________________________________________
Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony

Received on 2004-08-20