From 19cd73d69121c33d8d65cb0c4524cc5aa9084bd0 Mon Sep 17 00:00:00 2001 From: Li Cao Date: Tue, 16 Nov 2021 10:14:34 +0800 Subject: [PATCH] [settings] do not assert when SettingsFd is -1 in `Deinit` (#7170) We added a dry run option. So it is possible that the settings fd is -1 when de-initialization. The assert here makes the program crash. This commit updates it to a `VerifyOrExit` to avoid crashing. --- src/posix/platform/settings.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index eac81c235..ec105d9d5 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -226,8 +226,11 @@ void otPlatSettingsDeinit(otInstance *aInstance) otPosixSecureSettingsDeinit(aInstance); #endif - assert(sSettingsFd != -1); + VerifyOrExit(sSettingsFd != -1); VerifyOrDie(close(sSettingsFd) == 0, OT_EXIT_ERROR_ERRNO); + +exit: + return; } otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)