diff --git a/src/posix/platform/udp.cpp b/src/posix/platform/udp.cpp index 8993ca1b9..5151f51fd 100644 --- a/src/posix/platform/udp.cpp +++ b/src/posix/platform/udp.cpp @@ -240,7 +240,10 @@ otError otPlatUdpClose(otUdpSocket *aUdpSocket) otError error = OT_ERROR_NONE; int fd; - VerifyOrExit(aUdpSocket->mHandle != nullptr, error = OT_ERROR_INVALID_ARGS); + // Only call `close()` on platform UDP sockets. + // Platform UDP sockets always have valid `mHandle` upon creation. + VerifyOrExit(aUdpSocket->mHandle != nullptr); + fd = FdFromHandle(aUdpSocket->mHandle); VerifyOrExit(0 == close(fd), error = OT_ERROR_FAILED);