Export (0) Print
Expand All
Expand Minimize

freeaddrinfo function

The freeaddrinfofunction frees address information that the getaddrinfo function dynamically allocates in addrinfo structures.


void freeaddrinfo(
  _In_  struct addrinfo *ai


ai [in]

A pointer to the addrinfo structure or linked list of addrinfo structures to be freed. All dynamic storage pointed to within the addrinfo structure or structures is also freed.

Return value

This function does not return a value.


The freeaddrinfo function frees addrinfo structures dynamically allocated by the ANSI getaddrinfo function. The freeaddrinfo function frees the initial addrinfo structure pointed to in the ai parameter, including any buffers to which structure members point, then continues freeing any addrinfo structures linked by the ai_next member of the addrinfo structure. The freeaddrinfo function continues freeing linked structures until a NULL ai_next member is encountered.

Macros in the Winsock header file define a mixed-case function name of FreeAddrInfo and an ADDRINFOT structure. This FreeAddrInfo function should be called with the ai parameter of a pointer of type ADDRINFOT. When UNICODE or _UNICODE is not defined, FreeAddrInfo is defined to freeaddrinfo, the ANSI version of the function, and ADDRINFOT is defined to the addrinfo structure. When UNICODE or _UNICODE is defined, FreeAddrInfo is defined to FreeAddrInfoW, the Unicode version of the function, and ADDRINFOT is defined to the addrinfoW structure.

Support for freeaddrinfo on earlier versions of Windows

The freeaddrinfo function was added to the Ws2_32.dll on Windows XP and later. To execute an application using this function on earlier versions of Windows (Windows 2000, Windows NT, and Windows Me/98/95), then you must include the Ws2tcpip.h file and also include the Wspiapi.h file. When the Wspiapi.h include file is added, the freeaddrinfo function is defined to the WspiapiFreeAddrInfo inline function in the Wspiapi.h file. At runtime, the WspiapiFreeAddrInfo function is implemented in such a way that if the Ws2_32.dll or the Wship6.dll (the file containing freeaddrinfo in the IPv6 Technology Preview for Windows 2000) does not include freeaddrinfo, then a version of freeaddrinfo is implemented inline based on code in the Wspiapi.h header file. This inline code will be used on older Windows platforms that do not natively support the freeaddrinfo function.

The FreeAddrInfoW function is the Unicode version of freeaddrinfo. The FreeAddrInfoW function was added to the Ws2_32.dll in Windows XP with Service Pack 2 (SP2). The FreeAddrInfoW function cannot be used on versions of Windows earlier than Windows XP with SP2.

Windows Phone 8: This API is supported.


Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]


Ws2tcpip.h on Windows 2000 (include Wspiapi.h)



See also

Winsock Functions



Community Additions

© 2014 Microsoft