diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-11-02 08:26:55 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-11-02 08:26:55 +0000 |
commit | 186f433e4038b697b40f66a293f0f15332d055c4 (patch) | |
tree | f8fd7bad82e0c99561c1df927b2c0867a8dccb70 /docs/examples | |
parent | 736a40fec9a13fcad55e646189b3419a9280ab98 (diff) |
modified to not use realloc() on a NULL pointer
Diffstat (limited to 'docs/examples')
-rw-r--r-- | docs/examples/getinmemory.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 10ce8551f..5a77e9c7e 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; |