Skip to content

Commit

Permalink
[VL] Fix allocate and free memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhaliqi committed Jan 9, 2025
1 parent 73ee147 commit 8ba547b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cpp/core/benchmarks/CompressionBenchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions cpp/core/memory/MemoryAllocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,18 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t
return false;
}
memcpy(reallocatedP, p, std::min(size, newSize));
std::free(p);
if (p != nullptr) {
std::free(p);
}
*out = reallocatedP;
bytes_ += (newSize - size);
return true;
}

bool StdMemoryAllocator::free(void* p, int64_t size) {
std::free(p);
if (p != nullptr) {
std::free(p);
}
bytes_ -= size;
return true;
}
Expand Down

0 comments on commit 8ba547b

Please sign in to comment.