Skip to content

Commit

Permalink
frontend/GetVmId: Close WSL2 sockets and shell process (mintty/wsltty…
Browse files Browse the repository at this point in the history
  • Loading branch information
Biswa96 committed Sep 20, 2020
1 parent 1f16e1f commit 5ac3238
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/GetVmId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "LxssUserSession.hpp"
#include "WinHelper.hpp"

extern "C" {
WINBASEAPI int WINAPI closesocket(SOCKET s);
}

HRESULT GetVmId(
GUID *LxInstanceID,
const std::wstring &DistroName,
Expand Down Expand Up @@ -112,12 +116,26 @@ HRESULT GetVmId(
goto Cleanup;
}

/* ServerHandle and ServerSocket are exclusive */
if (ServerHandle == nullptr && ServerSocket != 0)
/* ServerHandle is for WSL1. So, nullptr for WSL2. */
if (ServerHandle == nullptr)
{
*WslVersion = WSL_VERSION_TWO;
else

/* wsltty#254: Closes extra shell process. */
if (SockIn) closesocket(SockIn);
if (SockOut) closesocket(SockOut);
if (SockErr) closesocket(SockErr);
}

/* ServerSocket is for WSL2. So, zero for WSL1. */
if (ServerSocket == 0)
{
*WslVersion = WSL_VERSION_ONE;

if (LxProcessHandle) CloseHandle(LxProcessHandle);
if (ServerHandle) CloseHandle(ServerHandle);
}

Cleanup:
if (wslSession)
wslSession->lpVtbl->Release(wslSession);
Expand Down

0 comments on commit 5ac3238

Please sign in to comment.