From a11df597078835c6acc4a36e7a98d00da3a30eaf 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 | 6 ++++++ 2 files changed, 9 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..bfadd3680f89 100644 --- a/cpp/core/memory/MemoryAllocator.cc +++ b/cpp/core/memory/MemoryAllocator.cc @@ -157,6 +157,9 @@ 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) { + if (p == nullptr) { + throw gluten::GlutenException("p is nullptr"); + } if (newSize <= 0) { return false; } @@ -179,6 +182,9 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t } bool StdMemoryAllocator::free(void* p, int64_t size) { + if (p == nullptr) { + throw gluten::GlutenException("p is nullptr"); + } std::free(p); bytes_ -= size; return true;