Skip to content

Commit 3fd90d3

Browse files
committed
chore(compilation): static analyser flag went mad.
1 parent d1de121 commit 3fd90d3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

utils/common/countingallocator.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class CountingAllocator
102102
, memoryLimitLowerBound_(other.memoryLimitLowerBound_)
103103
, checkPointStepSize_(other.checkPointStepSize_)
104104
{
105+
105106
}
106107

107108
// Allocate memory for n objects of type T
@@ -131,15 +132,17 @@ class CountingAllocator
131132
// Deallocate memory for n objects of type T
132133
void deallocate(T* ptr, std::size_t n) noexcept
133134
{
134-
::operator delete(ptr);
135-
135+
// Calculate all size-related values before deletion
136136
int64_t sizeToDeallocate = n * sizeof(T);
137-
138137
int64_t sizeChangeWDirection =
139138
(currentLocalMemoryUsage_ >= lastMemoryLimitCheckpoint_) ? -sizeToDeallocate : sizeToDeallocate;
140139
int64_t diffSinceLastCheckPoint = int_distance(currentLocalMemoryUsage_, lastMemoryLimitCheckpoint_);
140+
bool needsCheckpoint = needCheckPoint(sizeChangeWDirection, diffSinceLastCheckPoint, checkPointStepSize_);
141141

142-
if (needCheckPoint(sizeChangeWDirection, diffSinceLastCheckPoint, checkPointStepSize_))
142+
// Now safe to delete
143+
::operator delete(ptr);
144+
145+
if (needsCheckpoint)
143146
{
144147
// Invariant is lastMemoryLimitCheckpoint_ >= currentLocalMemoryUsage_ - sizeToDeallocate
145148
int64_t lastMemoryLimitCheckpointDiff =
@@ -148,11 +151,14 @@ class CountingAllocator
148151
: diffSinceLastCheckPoint + sizeToDeallocate;
149152

150153
assert(lastMemoryLimitCheckpointDiff > 0);
154+
151155
atomicops::atomicAddRef(*memoryLimit_, lastMemoryLimitCheckpointDiff);
152156

153157
lastMemoryLimitCheckpoint_ -= (lastMemoryLimitCheckpoint_ == 0) ? 0 : lastMemoryLimitCheckpointDiff;
154158
}
159+
155160
currentLocalMemoryUsage_ = currentLocalMemoryUsage_ - sizeToDeallocate;
161+
156162
}
157163

158164
// Equality operators (allocators are equal if they share the same counter)

0 commit comments

Comments
 (0)