Author: akhaldi Date: Tue Sep 20 09:42:51 2016 New Revision: 72747
URL: http://svn.reactos.org/svn/reactos?rev=72747&view=rev Log: [IPHLPAPI] Don't (de)initialize ws2 on dll process (attach/detach), do it on IcmpCreateFile/IcmpCloseHandle instead, due to the circular dependency ws2_32 -> mswsock -> dnsapi(adns lib) -> iphlpapi -> ws2_32. This creates 2 references to ws2_32 and ws2_32 can't cleanup on WSACleanup. By Peter Hater. CORE-10440
Modified: trunk/reactos/dll/win32/iphlpapi/icmp.c trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
Modified: trunk/reactos/dll/win32/iphlpapi/icmp.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/icmp.c?r... ============================================================================== --- trunk/reactos/dll/win32/iphlpapi/icmp.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/iphlpapi/icmp.c [iso-8859-1] Tue Sep 20 09:42:51 2016 @@ -114,8 +114,18 @@ HANDLE WINAPI Icmp6CreateFile(VOID) { icmp_t* icp; - - int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); + int sid; +#ifdef __REACTOS__ + WSADATA wsaData; + + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + { + ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); + return INVALID_HANDLE_VALUE; + } +#endif + + sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); #ifndef __REACTOS__ if (sid < 0) { @@ -133,6 +143,7 @@ if (icp==NULL) { #ifdef __REACTOS__ closesocket(sid); + WSACleanup(); #else close(sid); #endif @@ -180,8 +191,17 @@ static int once; #endif icmp_t* icp; - - int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); + int sid; +#ifdef __REACTOS__ + WSADATA wsaData; + + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + { + ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); + return INVALID_HANDLE_VALUE; + } +#endif + sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); #ifdef __REACTOS__ if (sid < 0) { ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n"); @@ -204,6 +224,7 @@ if (icp==NULL) { #ifdef __REACTOS__ closesocket(sid); + WSACleanup(); #else if (sid >= 0) close(sid); #endif @@ -235,6 +256,9 @@ if (icp->sid >= 0) close(icp->sid); #endif HeapFree(GetProcessHeap (), 0, icp); +#ifdef __REACTOS__ + WSACleanup(); +#endif return TRUE; }
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpapi... ============================================================================== --- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] Tue Sep 20 09:42:51 2016 @@ -35,17 +35,13 @@
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { - WSADATA wsaData; - switch (fdwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls( hinstDLL ); interfaceMapInit(); - WSAStartup(MAKEWORD(2, 2), &wsaData); break;
case DLL_PROCESS_DETACH: - WSACleanup(); interfaceMapFree(); break; }