Skip to content

Commit

Permalink
ARROW-238: Change InternalMemoryPool::Free() to return Status::Invali…
Browse files Browse the repository at this point in the history
…d when ther…

…e is insufficient memory.

Author: Jihoon Son <jihoonson@apache.org>

Closes #102 from jihoonson/ARROW-238 and squashes the following commits:

cb9e7b1 [Jihoon Son] Disable FreeLargeMemory test for release builds
f903130 [Jihoon Son] Free allocated memory after death
0077a70 [Jihoon Son] Adjust the amount of memory allocation
b1af59b [Jihoon Son] Change to ASSERT_EXIT
b4159f0 [Jihoon Son] Reflect comments
e89a1f9 [Jihoon Son] Change python implementation as well.
7651570 [Jihoon Son] Change InternalMemoryPool::Free() to return Status::Invalid when there is insufficient memory.
  • Loading branch information
jihoonson authored and wesm committed Jul 18, 2016
1 parent 62390d8 commit 55bfa83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace arrow {

#define ARROW_CHECK(condition) \
(condition) ? 0 : ::arrow::internal::FatalLog(ARROW_FATAL) \
<< __FILE__ << __LINE__ << "Check failed: " #condition " "
<< __FILE__ << __LINE__ << " Check failed: " #condition " "

#ifdef NDEBUG
#define ARROW_DFATAL ARROW_WARNING
Expand Down
14 changes: 14 additions & 0 deletions cpp/src/arrow/util/memory-pool-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ TEST(DefaultMemoryPool, OOM) {
ASSERT_RAISES(OutOfMemory, pool->Allocate(to_alloc, &data));
}

TEST(DefaultMemoryPoolDeathTest, FreeLargeMemory) {
MemoryPool* pool = default_memory_pool();

uint8_t* data;
ASSERT_OK(pool->Allocate(100, &data));

#ifndef NDEBUG
EXPECT_EXIT(pool->Free(data, 120), ::testing::ExitedWithCode(1),
".*Check failed: \\(bytes_allocated_\\) >= \\(size\\)");
#endif

pool->Free(data, 100);
}

} // namespace arrow
2 changes: 2 additions & 0 deletions cpp/src/arrow/util/memory-pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sstream>

#include "arrow/util/status.h"
#include "arrow/util/logging.h"

namespace arrow {

Expand Down Expand Up @@ -81,6 +82,7 @@ int64_t InternalMemoryPool::bytes_allocated() const {

void InternalMemoryPool::Free(uint8_t* buffer, int64_t size) {
std::lock_guard<std::mutex> guard(pool_lock_);
DCHECK_GE(bytes_allocated_, size);
std::free(buffer);
bytes_allocated_ -= size;
}
Expand Down

0 comments on commit 55bfa83

Please sign in to comment.