X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcmemory.c;h=b1a657b2f335593c91bba82875d9e2ea1d8fb8f6;hp=ec8eb1e39be41c7d7f214e0ba7ff21969d50334d;hb=9332a955b1c06b31268b6359b3c78f8e85daee04;hpb=eff4c7d3a6068f5feccd41d423824ff6180f4dc5 diff --git a/lib/silcutil/silcmemory.c b/lib/silcutil/silcmemory.c index ec8eb1e3..b1a657b2 100644 --- a/lib/silcutil/silcmemory.c +++ b/lib/silcutil/silcmemory.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1999 - 2007 Pekka Riikonen + Copyright (C) 1999 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -145,8 +145,20 @@ void *silc_scalloc(SilcStack stack, SilcUInt32 items, SilcUInt32 size) void *silc_srealloc(SilcStack stack, SilcUInt32 old_size, void *ptr, SilcUInt32 size) { - return stack ? silc_stack_realloc(stack, old_size, ptr, size) : - silc_realloc(ptr, size); + void *new_ptr; + + if (!stack) + return silc_realloc(ptr, size); + + new_ptr = silc_stack_realloc(stack, old_size, ptr, size); + if (!new_ptr) { + new_ptr = silc_smalloc(stack, size); + if (!new_ptr) + return NULL; + memcpy(new_ptr, ptr, old_size); + } + + return new_ptr; } void *silc_smemdup(SilcStack stack, const void *ptr, SilcUInt32 size)