From bf4233f1ecce5e359859ec70d95514846217d466 Mon Sep 17 00:00:00 2001 From: Hasti M Gondaliya Date: Fri, 13 Oct 2023 14:34:43 +0530 Subject: [PATCH] Coverity fix --- src/posix/platform/infra_if.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/posix/platform/infra_if.cpp b/src/posix/platform/infra_if.cpp index 505d025704ae..57159e5ddbd6 100644 --- a/src/posix/platform/infra_if.cpp +++ b/src/posix/platform/infra_if.cpp @@ -665,7 +665,7 @@ otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex) { otError error = OT_ERROR_NONE; struct addrinfo *hints = nullptr; - struct gaicb *reqs[1]; + struct gaicb *req = nullptr; struct sigevent sig; int status; @@ -676,18 +676,18 @@ otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex) hints->ai_family = AF_INET6; hints->ai_socktype = SOCK_STREAM; - reqs[0] = (struct gaicb *)malloc(sizeof(struct gaicb)); - VerifyOrExit(reqs[0] != nullptr, error = OT_ERROR_NO_BUFS); - memset(reqs[0], 0, sizeof(struct gaicb)); - reqs[0]->ar_name = kWellKnownIpv4OnlyName; - reqs[0]->ar_request = hints; + req = (struct gaicb *)malloc(sizeof(struct gaicb)); + VerifyOrExit(req != nullptr, error = OT_ERROR_NO_BUFS); + memset(req, 0, sizeof(struct gaicb)); + req->ar_name = kWellKnownIpv4OnlyName; + req->ar_request = hints; memset(&sig, 0, sizeof(struct sigevent)); sig.sigev_notify = SIGEV_THREAD; - sig.sigev_value.sival_ptr = reqs[0]; + sig.sigev_value.sival_ptr = req; sig.sigev_notify_function = &InfraNetif::DiscoverNat64PrefixDone; - status = getaddrinfo_a(GAI_NOWAIT, reqs, 1, &sig); + status = getaddrinfo_a(GAI_NOWAIT, &req, 1, &sig); if (status != 0) { @@ -702,7 +702,10 @@ otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex) { freeaddrinfo(hints); } - free(reqs[0]); + if (req) + { + free(req); + } } return error; }