Skip to content

Commit 633eb04

Browse files
committed
reverting realloc() block as it was cleaner before
1 parent 04c9c93 commit 633eb04

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

wled00/FX_fcn.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ bool Segment::allocateData(size_t len) {
160160
}
161161
// prefer DRAM over SPI RAM on ESP32 since it is slow
162162
if (data) {
163-
void* newData = d_realloc(data, len); // note: realloc returns null if it fails but does not free the original pointer
164-
if (!newData || newData != data) // realloc failed or used a new memory block causing fragmentation. free and allocate new block
165-
d_free(newData);
166-
d_free(data);
167-
data = nullptr; // reset pointer to null
163+
void* newData = d_realloc(data, len);
164+
if (newData) // realloc returns null if it fails but does not free the original pointer in that case
165+
data = (byte*)newData;
166+
else {
167+
d_free(data); // free old data if realloc failed
168+
data = nullptr; // reset pointer to null
168169
Segment::addUsedSegmentData(-_dataLen); // subtract original buffer size
169-
_dataLen = 0; // reset data length
170+
_dataLen = 0; // reset data length
171+
}
170172
}
171173
else data = (byte*)d_malloc(len);
172174

0 commit comments

Comments
 (0)