File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments