From: Daniel Stenberg Date: Tue, 2 Nov 2004 08:26:55 +0000 (+0000) Subject: modified to not use realloc() on a NULL pointer X-Git-Tag: curl-7_12_3~257 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=186f433e4038b697b40f66a293f0f15332d055c4;p=thirdparty%2Fcurl.git modified to not use realloc() on a NULL pointer --- diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 10ce8551f7..5a77e9c7e8 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -24,13 +24,23 @@ struct MemoryStruct { size_t size; }; +void *myrealloc(void *ptr, size_t size) +{ + /* There might be a realloc() out there that doesn't like reallocing + NULL pointers, so we take care of it here */ + if(ptr) + return realloc(ptr, size); + else + return malloc(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); + + mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize;