ws2_32: Always clear res on error in getaddrinfo/GetAddrInfoW.

This commit is contained in:
Hans Leidekker 2013-10-02 16:05:15 +02:00 committed by Alexandre Julliard
parent 59a1e6bff9
commit 14a092a336
2 changed files with 35 additions and 4 deletions

View file

@ -5397,6 +5397,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
char *hostname = NULL;
const char *node;
*res = NULL;
if (!nodename && !servname) return WSAHOST_NOT_FOUND;
if (!nodename)
@ -5479,16 +5480,14 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
xuai = xuai->ai_next;
}
freeaddrinfo(unixaires);
} else {
} else
result = convert_eai_u2w(result);
*res = NULL;
}
return result;
outofmem:
if (*res) WS_freeaddrinfo(*res);
if (unixaires) freeaddrinfo(unixaires);
*res = NULL;
return WSA_NOT_ENOUGH_MEMORY;
#else
FIXME("getaddrinfo() failed, not found during buildtime.\n");
@ -5595,6 +5594,7 @@ int WINAPI GetAddrInfoW(LPCWSTR nodename, LPCWSTR servname, const ADDRINFOW *hin
char *nodenameA = NULL, *servnameA = NULL;
struct WS_addrinfo *resA, *hintsA = NULL;
*res = NULL;
if (nodename)
{
len = WideCharToMultiByte(CP_ACP, 0, nodename, -1, NULL, 0, NULL, NULL);

View file

@ -5092,6 +5092,8 @@ static void test_GetAddrInfoW(void)
static const WCHAR port[] = {'8','0',0};
static const WCHAR empty[] = {0};
static const WCHAR localhost[] = {'l','o','c','a','l','h','o','s','t',0};
static const WCHAR nxdomain[] =
{'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
static const WCHAR zero[] = {'0',0};
int ret;
ADDRINFOW *result, hint;
@ -5103,8 +5105,10 @@ static void test_GetAddrInfoW(void)
}
memset(&hint, 0, sizeof(ADDRINFOW));
result = (ADDRINFOW *)0xdeadbeef;
ret = pGetAddrInfoW(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(result == NULL, "got %p\n", result);
result = NULL;
ret = pGetAddrInfoW(empty, NULL, NULL, &result);
@ -5144,10 +5148,25 @@ static void test_GetAddrInfoW(void)
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
pFreeAddrInfoW(result);
result = NULL;
ret = pGetAddrInfoW(localhost, NULL, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
pFreeAddrInfoW(result);
result = NULL;
ret = pGetAddrInfoW(localhost, port, &hint, &result);
ok(!ret, "GetAddrInfoW failed with %d\n", WSAGetLastError());
pFreeAddrInfoW(result);
result = (ADDRINFOW *)0xdeadbeef;
ret = pGetAddrInfoW(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(result == NULL, "got %p\n", result);
result = (ADDRINFOW *)0xdeadbeef;
ret = pGetAddrInfoW(nxdomain, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(result == NULL, "got %p\n", result);
}
static void test_getaddrinfo(void)
@ -5162,8 +5181,10 @@ static void test_getaddrinfo(void)
}
memset(&hint, 0, sizeof(ADDRINFOA));
result = (ADDRINFOA *)0xdeadbeef;
ret = pgetaddrinfo(NULL, NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(result == NULL, "got %p\n", result);
result = NULL;
ret = pgetaddrinfo("", NULL, NULL, &result);
@ -5203,10 +5224,20 @@ static void test_getaddrinfo(void)
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
pfreeaddrinfo(result);
result = NULL;
ret = pgetaddrinfo("localhost", NULL, &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
pfreeaddrinfo(result);
result = NULL;
ret = pgetaddrinfo("localhost", "80", &hint, &result);
ok(!ret, "getaddrinfo failed with %d\n", WSAGetLastError());
pfreeaddrinfo(result);
result = (ADDRINFOA *)0xdeadbeef;
ret = pgetaddrinfo("nxdomain.codeweavers.com", NULL, NULL, &result);
ok(ret == WSAHOST_NOT_FOUND, "got %d expected WSAHOST_NOT_FOUND\n", ret);
ok(result == NULL, "got %p\n", result);
}
static void test_ConnectEx(void)