cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Sending SOAP query using CURLOPT_POST not working for me

From: Lars Nilsson <chamaeleon_at_gmail.com>
Date: Mon, 4 Jan 2010 17:46:26 -0500

On Mon, Jan 4, 2010 at 5:28 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Mon, 4 Jan 2010, Lars Nilsson wrote:
>
>>>>        mem->memory = (char *)realloc(mem->memory, mem->size + realsize
>>>> + 1);                 // Application crashes here.
>>>
>>> Well yes, as 'mem' is NULL...
>>
>> realloc() shouldn't have a problem dealing with a NULL pointer.
>
> Right, but the code never reaches realloc(). Read the code again and notice
> that 'mem' is NULL in the above scenario. It will try to read data from a
> struct at adress 0x0 and that won't work. 'mem->memory' is illegal (and so
> is mem->size).

       if ((bodyStruct = (struct MemoryStruct *) malloc(sizeof(struct
MemoryStruct))) == NULL) exit(1);
       curl_easy_setopt(ch, CURLOPT_FILE, bodyStruct);

Isn't mem in the callback function the allocated value of bodyStruct?
My guess is simply that while bodyStruct/mem is valid allocated
memory, mem->memory for instance is not, and realloc would choke on an
invalid, non-null, memory reference being passed as memory to
reallocate. Using calloc() or memset() for instance could be a
solution to the immediate problem.

Lars Nilsson
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-01-04