cURL / Mailing Lists / curl-library / Single Mail


Re: Modifying the example source code

From: Alan Wolfe <>
Date: Sun, 27 Feb 2011 22:28:16 -0800


the malloc(1) isn't being stingy. As the comments say, it will be
resized with realloc calls later on.

Basically, it allocates a single byte so there's a valid memory
address in chunk.memory so that realloc can be called on it later on.
If it started out NULL, there would have to be an if check before the
realloc call, so it just simplifies things a little.

as far as the chunk.size, that is saying how much data there is. It
should be set to 0 starting out because when data comes in, it will
get changed to something else later on.

If you set it to 10000 starting out, the code will think there is 10k
of data that isn't really there which im sure is causing your

Hope this helps!

On Sun, Feb 27, 2011 at 8:37 PM, <> wrote:
> Hi everyone.  I'm still a newb trying to learn C99 and use libcurl.
> I have successfully modified this code:
> It works perfectly.  However, where it says chunk.memory = malloc (1) , I
> decided to be less stingy and give it malloc (10000).  Now, I modify the
> next line to chunk.size = 10000 ; and suddenly my code produces errors.
> Am I misunderstanding the purpose of MemoryStruct.size ?
> Richard
> -------------------------------------------------------------------
> List admin:
> Etiquette:

List admin:
Received on 2011-02-28