From eb74a7490ef4073f6492147ccb2e1f990c96a88b Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Mon, 8 Feb 2021 15:07:38 +0000
Subject: [PATCH] Allow allocation of 0 bytes in SparseAllocator, but return
 NULL to avoid needing extra memory (we define our Arenas rather tight)

---
 RTCP/Cobalt/CoInterface/src/Allocator.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/RTCP/Cobalt/CoInterface/src/Allocator.cc b/RTCP/Cobalt/CoInterface/src/Allocator.cc
index d7ff56675a6..2b15c4eccc5 100644
--- a/RTCP/Cobalt/CoInterface/src/Allocator.cc
+++ b/RTCP/Cobalt/CoInterface/src/Allocator.cc
@@ -121,7 +121,8 @@ namespace LOFAR
       ScopedLock sl(mutex);
 
       // if we allocate 0 bytes, we could end up returning the same pointer for a subsequent allocation.
-      if (size == 0) size = 1;
+      // since allocations with 0 bytes shouldn't be dereferenced anyway, we return NULL.
+      if (size == 0) return 0;
 
       // look for a free range large enough
       for (SparseSet<void *>::const_iterator it = freeList.getRanges().begin(); it != freeList.getRanges().end(); it++) {
-- 
GitLab