From f4c3ec4954faf34b35fb393e7d70b438b17d3bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Kristan?= Date: Tue, 17 Feb 2026 13:47:20 +0100 Subject: [PATCH] Delayed malloc PR fix --- src/internal/methods/NeoEsp32I2sXMethod.h | 1 + src/internal/methods/NeoEsp32LcdXMethod.h | 2 +- src/internal/methods/NeoEsp8266DmaMethod.h | 2 +- .../methods/NeoEsp8266I2sDmx512Method.h | 2 +- .../methods/NeoEsp8266I2sMethodCore.h | 22 +++++++++++++++++-- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/internal/methods/NeoEsp32I2sXMethod.h b/src/internal/methods/NeoEsp32I2sXMethod.h index 0c945fb3..fa7d3739 100644 --- a/src/internal/methods/NeoEsp32I2sXMethod.h +++ b/src/internal/methods/NeoEsp32I2sXMethod.h @@ -838,6 +838,7 @@ class NeoEsp32I2sXMethodBase if (_data == nullptr) { log_e("front buffer memory allocation failure"); + _bus.DeregisterMuxBus(_pin); // TODO: not sure if it is needed return false; } return true; diff --git a/src/internal/methods/NeoEsp32LcdXMethod.h b/src/internal/methods/NeoEsp32LcdXMethod.h index e7a82541..09ac2030 100644 --- a/src/internal/methods/NeoEsp32LcdXMethod.h +++ b/src/internal/methods/NeoEsp32LcdXMethod.h @@ -649,7 +649,7 @@ class NeoEsp32LcdXMethodBase if (_data == nullptr) { log_e("front buffer memory allocation failure"); - _bus.Destruct() + _bus.DeregisterMuxBus(_pin); // TODO: not sure if it is needed return false; } return true; diff --git a/src/internal/methods/NeoEsp8266DmaMethod.h b/src/internal/methods/NeoEsp8266DmaMethod.h index 64a3c2a7..f76ce98d 100644 --- a/src/internal/methods/NeoEsp8266DmaMethod.h +++ b/src/internal/methods/NeoEsp8266DmaMethod.h @@ -248,7 +248,7 @@ template class NeoEsp8266DmaMethodBase : N return false; } - if (!AllocateI2s()) + if (!AllocateI2s(T_ENCODER::IdleLevel)) { free(_data); _data = nullptr; diff --git a/src/internal/methods/NeoEsp8266I2sDmx512Method.h b/src/internal/methods/NeoEsp8266I2sDmx512Method.h index 3e14748f..72099a5b 100644 --- a/src/internal/methods/NeoEsp8266I2sDmx512Method.h +++ b/src/internal/methods/NeoEsp8266I2sDmx512Method.h @@ -194,7 +194,7 @@ template class NeoEsp8266I2sDmx512MethodBase : NeoEsp8266I2sMe return false; } - if (!AllocateI2s()) + if (!AllocateI2s(T_SPEED::MtbpLevel)) { free(_data); _data = nullptr; diff --git a/src/internal/methods/NeoEsp8266I2sMethodCore.h b/src/internal/methods/NeoEsp8266I2sMethodCore.h index e6e0a7f7..e181c67d 100644 --- a/src/internal/methods/NeoEsp8266I2sMethodCore.h +++ b/src/internal/methods/NeoEsp8266I2sMethodCore.h @@ -169,16 +169,34 @@ class NeoEsp8266I2sMethodCore } - void AllocateI2s() + bool AllocateI2s(const uint8_t idleLevel) { _i2sBuffer = static_cast(malloc(_i2sBufferSize)); - // no need to initialize it, it gets overwritten on every send + if (!_i2sBuffer) + { + return false; + } _i2sIdleData = static_cast(malloc(_i2sIdleDataSize)); + if (!_i2sIdleData) + { + free(_i2sBuffer); + _i2sBuffer = nullptr; + return false; + } memset(_i2sIdleData, idleLevel * 0xff, _i2sIdleDataSize); _i2sBufDesc = (slc_queue_item*)malloc(_i2sBufDescCount * sizeof(slc_queue_item)); + if (!_i2sBufDesc) + { + free(_i2sBuffer); + free(_i2sIdleData); + _i2sBuffer = nullptr; + _i2sIdleData = nullptr; + return false; + } s_this = this; // store this for the ISR + return true; } void FreeI2s()