1818
1919#include < cstdint>
2020#include < memory>
21+ #include < new>
2122#include < string>
2223
2324#include " arrow/memory_pool.h"
@@ -33,18 +34,30 @@ class ArrowMemPoolAdaptor : public arrow::MemoryPool {
3334 : pool_(*pool), life_holder_(pool) {}
3435
3536 arrow::Status Allocate (int64_t size, int64_t alignment, uint8_t ** out) override {
36- *out = reinterpret_cast <uint8_t *>(pool_.Malloc (size, alignment));
37- if (size > 0 && *out == nullptr ) {
37+ uint8_t * new_out = nullptr ;
38+ try {
39+ new_out = reinterpret_cast <uint8_t *>(pool_.Malloc (size, alignment));
40+ } catch (const std::bad_alloc&) {
3841 return arrow::Status::OutOfMemory (fmt::format (" failed to allocate {} bytes" , size));
3942 }
43+ if (size > 0 && new_out == nullptr ) {
44+ return arrow::Status::OutOfMemory (fmt::format (" failed to allocate {} bytes" , size));
45+ }
46+ *out = new_out;
4047 stats_.DidAllocateBytes (size);
4148 return arrow::Status::OK ();
4249 }
4350
4451 arrow::Status Reallocate (int64_t old_size, int64_t new_size, int64_t alignment,
4552 uint8_t ** ptr) override {
46- auto * new_ptr =
47- reinterpret_cast <uint8_t *>(pool_.Realloc (*ptr, old_size, new_size, alignment));
53+ uint8_t * new_ptr = nullptr ;
54+ try {
55+ new_ptr =
56+ reinterpret_cast <uint8_t *>(pool_.Realloc (*ptr, old_size, new_size, alignment));
57+ } catch (const std::bad_alloc&) {
58+ return arrow::Status::OutOfMemory (
59+ fmt::format (" failed to reallocate memory from {} to {} bytes" , old_size, new_size));
60+ }
4861 if (new_size > 0 && new_ptr == nullptr ) {
4962 return arrow::Status::OutOfMemory (
5063 fmt::format (" failed to reallocate memory from {} to {} bytes" , old_size, new_size));
0 commit comments