Skip to content

Commit

Permalink
Coverity fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hastigondaliya committed Oct 16, 2023
1 parent 17e433c commit bf4233f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/posix/platform/infra_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand All @@ -702,7 +702,10 @@ otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex)
{
freeaddrinfo(hints);
}
free(reqs[0]);
if (req)
{
free(req);
}
}
return error;
}
Expand Down

0 comments on commit bf4233f

Please sign in to comment.