From ef83329b3641e88d6edbec19cc89372d5c6d6324 Mon Sep 17 00:00:00 2001 From: Jacob Khaliqi Date: Wed, 8 Jan 2025 15:38:59 -0800 Subject: [PATCH] [VL] Fix allocate and free memory --- cpp/core/benchmarks/CompressionBenchmark.cc | 4 +++- cpp/core/memory/MemoryAllocator.cc | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cpp/core/benchmarks/CompressionBenchmark.cc b/cpp/core/benchmarks/CompressionBenchmark.cc index e1aa69ff39a7..da8c71c044ba 100644 --- a/cpp/core/benchmarks/CompressionBenchmark.cc +++ b/cpp/core/benchmarks/CompressionBenchmark.cc @@ -48,7 +48,9 @@ void printTrace(void) { for (i = 0; i < size; i++) printf(" %s\n", strings[i]); puts(""); - free(strings); + if (strings != nullptr) { + free(strings); + } } using arrow::RecordBatchReader; diff --git a/cpp/core/memory/MemoryAllocator.cc b/cpp/core/memory/MemoryAllocator.cc index dd5fb8e1974b..84708962d01c 100644 --- a/cpp/core/memory/MemoryAllocator.cc +++ b/cpp/core/memory/MemoryAllocator.cc @@ -157,6 +157,7 @@ bool StdMemoryAllocator::reallocate(void* p, int64_t size, int64_t newSize, void } bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t size, int64_t newSize, void** out) { + GLUTEN_CHECK(p != nullptr, "reallocate with nullptr"); if (newSize <= 0) { return false; } @@ -179,6 +180,7 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t } bool StdMemoryAllocator::free(void* p, int64_t size) { + GLUTEN_CHECK(p != nullptr, "free with nullptr"); std::free(p); bytes_ -= size; return true;