diff --git a/cpp/src/arrow/memory_pool.cc b/cpp/src/arrow/memory_pool.cc index 34bd600e..3ef32090 100644 --- a/cpp/src/arrow/memory_pool.cc +++ b/cpp/src/arrow/memory_pool.cc @@ -53,6 +53,7 @@ Status AllocateAligned(int64_t size, uint8_t** out) { ss << "malloc of size " << size << " failed"; return Status::OutOfMemory(ss.str()); } + memset(*out, 0, size); #elif defined(ARROW_JEMALLOC) *out = reinterpret_cast(mallocx( std::max(static_cast(size), kAlignment), MALLOCX_ALIGN(kAlignment))); @@ -75,6 +76,7 @@ Status AllocateAligned(int64_t size, uint8_t** out) { ss << "invalid alignment parameter: " << kAlignment; return Status::Invalid(ss.str()); } + memset(*out, 0, size); #endif return Status::OK(); } @@ -124,6 +126,9 @@ class DefaultMemoryPool : public MemoryPool { DCHECK(out); // Copy contents and release old memory chunk memcpy(out, *ptr, static_cast(std::min(new_size, old_size))); + if (new_size > old_size) { + memset(out + old_size, 0, static_cast(new_size - old_size)); + } #ifdef _MSC_VER _aligned_free(*ptr); #else