Skip to content

Commit

Permalink
[posix] Addressing coverity warning: Resource leak
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hastigondaliya committed Sep 29, 2023
1 parent bd63637 commit 5f31554
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/posix/platform/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 5f31554

Please sign in to comment.