diff --git a/dll/win32/msafd/misc/sndrcv.c b/dll/win32/msafd/misc/sndrcv.c index 28755b85452d4..7f56556a99905 100644 --- a/dll/win32/msafd/misc/sndrcv.c +++ b/dll/win32/msafd/misc/sndrcv.c @@ -789,8 +789,6 @@ WSPSendTo(SOCKET Handle, PIO_APC_ROUTINE APCFunction; HANDLE Event = NULL; PTRANSPORT_ADDRESS RemoteAddress; - PSOCKADDR BindAddress = NULL; - INT BindAddressLength; HANDLE SockEvent; PSOCKET_INFORMATION Socket; @@ -828,6 +826,10 @@ WSPSendTo(SOCKET Handle, /* Bind us First */ if (Socket->SharedData->State == SocketOpen) { + INT BindAddressLength; + PSOCKADDR BindAddress; + INT BindError; + /* Get the Wildcard Address */ BindAddressLength = Socket->HelperData->MaxWSAddressLength; BindAddress = HeapAlloc(GlobalHeap, 0, BindAddressLength); @@ -841,17 +843,15 @@ WSPSendTo(SOCKET Handle, BindAddress, &BindAddressLength); /* Bind it */ - if (WSPBind(Handle, BindAddress, BindAddressLength, lpErrno) == SOCKET_ERROR) + BindError = WSPBind(Handle, BindAddress, BindAddressLength, lpErrno); + HeapFree(GlobalHeap, 0, BindAddress); + if (BindError == SOCKET_ERROR) return SOCKET_ERROR; } RemoteAddress = HeapAlloc(GlobalHeap, 0, 0x6 + SocketAddressLength); if (!RemoteAddress) { - if (BindAddress != NULL) - { - HeapFree(GlobalHeap, 0, BindAddress); - } return MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, NULL); } @@ -862,10 +862,6 @@ WSPSendTo(SOCKET Handle, if (!NT_SUCCESS(Status)) { HeapFree(GlobalHeap, 0, RemoteAddress); - if (BindAddress != NULL) - { - HeapFree(GlobalHeap, 0, BindAddress); - } return SOCKET_ERROR; } @@ -896,6 +892,8 @@ WSPSendTo(SOCKET Handle, if ((Socket->SharedData->CreateFlags & SO_SYNCHRONOUS_NONALERT) != 0) { TRACE("Opened without flag WSA_FLAG_OVERLAPPED. Do nothing.\n"); + NtClose(SockEvent); + HeapFree(GlobalHeap, 0, RemoteAddress); return MsafdReturnWithErrno(STATUS_SUCCESS, lpErrno, 0, lpNumberOfBytesSent); } if (lpCompletionRoutine == NULL) @@ -913,6 +911,8 @@ WSPSendTo(SOCKET Handle, if (!APCContext) { ERR("Not enough memory for APC Context\n"); + NtClose(SockEvent); + HeapFree(GlobalHeap, 0, RemoteAddress); return MsafdReturnWithErrno(STATUS_INSUFFICIENT_RESOURCES, lpErrno, 0, lpNumberOfBytesSent); } APCContext->lpCompletionRoutine = lpCompletionRoutine; @@ -950,10 +950,6 @@ WSPSendTo(SOCKET Handle, NtClose(SockEvent); HeapFree(GlobalHeap, 0, RemoteAddress); - if (BindAddress != NULL) - { - HeapFree(GlobalHeap, 0, BindAddress); - } if (Status == STATUS_PENDING) {