From a6caf556ef02e21220a14b7b5b072a876752a815 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 4 Jun 2018 22:43:38 +0300 Subject: [PATCH] Fixed potential issue found by PVS-Studio [#CLICKHOUSE-3] --- dbms/src/Common/Allocator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dbms/src/Common/Allocator.cpp b/dbms/src/Common/Allocator.cpp index 39f7d85608e..5c653a9a1c9 100644 --- a/dbms/src/Common/Allocator.cpp +++ b/dbms/src/Common/Allocator.cpp @@ -123,11 +123,11 @@ void * Allocator::realloc(void * buf, size_t old_size, size_t new { CurrentMemoryTracker::realloc(old_size, new_size); - buf = ::realloc(buf, new_size); - - if (nullptr == buf) + void * new_buf = ::realloc(buf, new_size); + if (nullptr == new_buf) DB::throwFromErrno("Allocator: Cannot realloc from " + formatReadableSizeWithBinarySuffix(old_size) + " to " + formatReadableSizeWithBinarySuffix(new_size) + ".", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY); + buf = new_buf; if (clear_memory && new_size > old_size) memset(reinterpret_cast(buf) + old_size, 0, new_size - old_size); }