- Add error handling for Opensolaris f***ing up a numeric getnameinfo() call.

- Fix memory leak in getaddrinfo() call
Many thanks to Ben Millwood for reporting this.
This commit is contained in:
Thilo Schulz 2009-06-26 18:11:45 +00:00
parent 948f7a6015
commit 9b2b9abd25

View file

@ -341,7 +341,8 @@ static void Sys_SockaddrToString(char *dest, int destlen, struct sockaddr *input
else else
inputlen = sizeof(struct sockaddr_in); inputlen = sizeof(struct sockaddr_in);
getnameinfo(input, inputlen, dest, destlen, NULL, 0, NI_NUMERICHOST); if(getnameinfo(input, inputlen, dest, destlen, NULL, 0, NI_NUMERICHOST) && destlen > 0)
*dest = '\0';
} }
/* /*
@ -1319,9 +1320,6 @@ void NET_GetLocalAddress( void ) {
char hostname[256]; char hostname[256];
struct addrinfo hint; struct addrinfo hint;
struct addrinfo *res = NULL; struct addrinfo *res = NULL;
struct addrinfo *search;
struct sockaddr_in mask4;
struct sockaddr_in6 mask6;
if(gethostname( hostname, 256 ) == SOCKET_ERROR) if(gethostname( hostname, 256 ) == SOCKET_ERROR)
return; return;
@ -1333,8 +1331,11 @@ void NET_GetLocalAddress( void ) {
hint.ai_family = AF_UNSPEC; hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_DGRAM; hint.ai_socktype = SOCK_DGRAM;
if(getaddrinfo(hostname, NULL, &hint, &res)) if(!getaddrinfo(hostname, NULL, &hint, &res))
return; {
struct sockaddr_in mask4;
struct sockaddr_in6 mask6;
struct addrinfo *search;
/* On operating systems where it's more difficult to find out the configured interfaces, we'll just assume a /* On operating systems where it's more difficult to find out the configured interfaces, we'll just assume a
* netmask with all bits set. */ * netmask with all bits set. */
@ -1357,6 +1358,10 @@ void NET_GetLocalAddress( void ) {
Sys_ShowIP(); Sys_ShowIP();
} }
if(res)
freeaddrinfo(res);
}
#endif #endif
/* /*