diff --git a/cpp/src/arrow/memory_pool.cc b/cpp/src/arrow/memory_pool.cc index b8cd9c2fcf9..dedab7ea729 100644 --- a/cpp/src/arrow/memory_pool.cc +++ b/cpp/src/arrow/memory_pool.cc @@ -107,10 +107,12 @@ class DefaultMemoryPool : public MemoryPool { Status Reallocate(int64_t old_size, int64_t new_size, uint8_t** ptr) override { #ifdef ARROW_JEMALLOC + uint8_t* previous_ptr = *ptr; *ptr = reinterpret_cast(rallocx(*ptr, new_size, MALLOCX_ALIGN(kAlignment))); if (*ptr == NULL) { std::stringstream ss; ss << "realloc of size " << new_size << " failed"; + *ptr = previous_ptr; return Status::OutOfMemory(ss.str()); } #else