From ae27aaaf4304d43828a6d2597993ee3b46038ab2 Mon Sep 17 00:00:00 2001 From: Tom Fifield Date: Fri, 21 Mar 2025 21:54:42 +1100 Subject: [PATCH] Remove unnecessary null pointer checks (#6358) As reported by @elfring, we had several points in our code where it was unnecessary to check pointers were non-null before deleting them. Fixes https://github.com/meshtastic/firmware/issues/6170 --- src/AudioThread.h | 6 ++---- src/mesh/CryptoEngine.cpp | 6 ++---- src/motion/AccelerometerThread.h | 8 +++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/AudioThread.h b/src/AudioThread.h index 6d560ec55..04ff64a6e 100644 --- a/src/AudioThread.h +++ b/src/AudioThread.h @@ -41,10 +41,8 @@ class AudioThread : public concurrency::OSThread delete i2sRtttl; i2sRtttl = nullptr; } - if (rtttlFile != nullptr) { - delete rtttlFile; - rtttlFile = nullptr; - } + delete rtttlFile; + rtttlFile = nullptr; setCPUFast(false); } diff --git a/src/mesh/CryptoEngine.cpp b/src/mesh/CryptoEngine.cpp index 4613a6218..6dffbe2b7 100644 --- a/src/mesh/CryptoEngine.cpp +++ b/src/mesh/CryptoEngine.cpp @@ -161,10 +161,8 @@ void CryptoEngine::hash(uint8_t *bytes, size_t numBytes) void CryptoEngine::aesSetKey(const uint8_t *key_bytes, size_t key_len) { - if (aes) { - delete aes; - aes = nullptr; - } + delete aes; + aes = nullptr; if (key_len != 0) { aes = new AESSmall256(); aes->setKey(key_bytes, key_len); diff --git a/src/motion/AccelerometerThread.h b/src/motion/AccelerometerThread.h index 6e517d6b0..dd6413d64 100755 --- a/src/motion/AccelerometerThread.h +++ b/src/motion/AccelerometerThread.h @@ -160,13 +160,11 @@ class AccelerometerThread : public concurrency::OSThread void clean() { isInitialised = false; - if (sensor != nullptr) { - delete sensor; - sensor = nullptr; - } + delete sensor; + sensor = nullptr; } }; #endif -#endif \ No newline at end of file +#endif