kwin: fix crash in case of getaddrinfo() failure in client machine test

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-05-23 02:21:39 +03:00
parent 56f58144c7
commit 9b9a39951c

View file

@ -75,7 +75,7 @@ void TestClientMachine::initTestCase()
hostnamebuf[sizeof(hostnamebuf)-1] = 0; hostnamebuf[sizeof(hostnamebuf)-1] = 0;
m_hostName = hostnamebuf; m_hostName = hostnamebuf;
} }
addrinfo *res; addrinfo *res = NULL;
addrinfo addressHints; addrinfo addressHints;
memset(&addressHints, 0, sizeof(addressHints)); memset(&addressHints, 0, sizeof(addressHints));
addressHints.ai_family = PF_UNSPEC; addressHints.ai_family = PF_UNSPEC;
@ -86,7 +86,9 @@ void TestClientMachine::initTestCase()
m_fqdn = QByteArray(res->ai_canonname); m_fqdn = QByteArray(res->ai_canonname);
} }
} }
freeaddrinfo(res); if (res) {
freeaddrinfo(res);
}
} }
void TestClientMachine::cleanupTestCase() void TestClientMachine::cleanupTestCase()
@ -148,4 +150,5 @@ void TestClientMachine::emptyHostName()
} }
KWIN_TEST_MAIN(TestClientMachine) KWIN_TEST_MAIN(TestClientMachine)
#include "test_client_machine.moc" #include "test_client_machine.moc"