dbms: fixed error with memory tracking [#METR-16433].

This commit is contained in:
Alexey Milovidov 2015-06-08 07:59:45 +03:00
parent 51be2693ee
commit 97782b4855

View File

@ -151,20 +151,18 @@ public:
void * realloc(void * buf, size_t old_size, size_t new_size) void * realloc(void * buf, size_t old_size, size_t new_size)
{ {
/// Было в stack_memory, там и останется.
if (new_size <= N) if (new_size <= N)
return buf; return buf;
/// Уже не помещалось в stack_memory.
if (old_size > N) if (old_size > N)
return HashTableAllocator::realloc(buf, old_size, new_size); return HashTableAllocator::realloc(buf, old_size, new_size);
buf = ::malloc(new_size); /// Было в stack_memory, но теперь не помещается.
if (nullptr == buf) void * new_buf = HashTableAllocator::alloc(new_size);
DB::throwFromErrno("HashTableAllocator: Cannot malloc.", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY); memcpy(new_buf, buf, old_size);
return new_buf;
memcpy(buf, stack_memory, old_size);
memset(reinterpret_cast<char *>(buf) + old_size, 0, new_size - old_size);
return buf;
} }
}; };