From ede7c28eb7a19e9bc032183abaa762d05373a712 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 7 Oct 2003 12:09:42 +0000 Subject: [PATCH] In realloc, don't destroy the old memory area if a new one couldn't be allocated. Notified by Daniel Lucq --- crypto/mem.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crypto/mem.c b/crypto/mem.c index 29df7d35b2..bb862db499 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -352,11 +352,15 @@ void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file, realloc_debug_func(str, NULL, num, file, line, 0); ret=malloc_ex_func(num,file,line); if(ret) + { memcpy(ret,str,old_len); - OPENSSL_cleanse(str,old_len); - free_func(str); + OPENSSL_cleanse(str,old_len); + free_func(str); + } #ifdef LEVITTE_DEBUG_MEM - fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num); + fprintf(stderr, + "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", + str, ret, num); #endif if (realloc_debug_func != NULL) realloc_debug_func(str, ret, num, file, line, 1); -- 2.25.1