From 5f31554667cf72bcb01247f637b9eb9e4859008e Mon Sep 17 00:00:00 2001 From: Hasti M Gondaliya Date: Fri, 29 Sep 2023 15:25:41 +0530 Subject: [PATCH] [posix] Addressing coverity warning: Resource leak The "assert" and "VerifyOrDie" were checking same condition, so the second validation was never executed if (rval != sizeof(key)). Additionally,"aSwapFd" was not freed on assertion. With this commit, addressed the memory leak to system resources. --- src/posix/platform/settings.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/posix/platform/settings.cpp b/src/posix/platform/settings.cpp index 73925fe21500..a0ccd39f0acb 100644 --- a/src/posix/platform/settings.cpp +++ b/src/posix/platform/settings.cpp @@ -474,12 +474,18 @@ otError PlatformSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex, } rval = write(swapFd, &key, sizeof(key)); - assert(rval == sizeof(key)); - VerifyOrDie(rval == sizeof(key), OT_EXIT_FAILURE); + if(rval != sizeof(key)) + { + swapDiscard(aInstance, swapFd); + VerifyOrDie(rval == sizeof(key), OT_EXIT_FAILURE); + } rval = write(swapFd, &length, sizeof(length)); - assert(rval == sizeof(length)); - VerifyOrDie(rval == sizeof(length), OT_EXIT_FAILURE); + if(rval != sizeof(length)) + { + swapDiscard(aInstance, swapFd); + VerifyOrDie(rval == sizeof(length), OT_EXIT_FAILURE); + } swapWrite(aInstance, swapFd, length); }