From 783d76fe73a589c7e97fed0f299ddff57d0ebf00 Mon Sep 17 00:00:00 2001 From: james-sumihiro Date: Fri, 12 Jan 2024 16:53:01 -0800 Subject: [PATCH] Fix two handle leaks during remote probe Added logic to the entry point RENDERDOC_CreateRemoteServerConnection to shutdown the socket used to connect to a remote device when the function is used to test a connection (IRemoteServer **rend is null.) This previously created a handle leak, visible as accumulating /device/afd/ file handles on Windows. Added logic to the Windows specialization of Process::LaunchProcess so it will close two handles: hChildStdError_Rd, and hChildStdOutput_Rd if the handles were created successfully but the process failed to launch. Previously these would accumulate during a remote probe for Android devices if ADB was not present or otherwise failed to launch. --- renderdoc/core/remote_server.cpp | 3 +++ renderdoc/os/win32/win32_process.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index 66b1d6b26..bdc882e39 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -1247,7 +1247,10 @@ RENDERDOC_CreateRemoteServerConnection(const rdcstr &URL, IRemoteServer **rend) } if(rend == NULL) + { + SAFE_DELETE(sock); return RDResult(ResultCode::Succeeded); + } if(protocol) *rend = protocol->CreateRemoteServer(sock, deviceID); diff --git a/renderdoc/os/win32/win32_process.cpp b/renderdoc/os/win32/win32_process.cpp index e299fdefa..7795905dc 100644 --- a/renderdoc/os/win32/win32_process.cpp +++ b/renderdoc/os/win32/win32_process.cpp @@ -1060,6 +1060,12 @@ uint32_t Process::LaunchProcess(const rdcstr &app, const rdcstr &workingDir, con { if(!internal) RDCWARN("Couldn't launch process '%s'", appPath.c_str()); + + if(hChildStdError_Rd != NULL) + CloseHandle(hChildStdError_Rd); + if(hChildStdOutput_Rd != NULL) + CloseHandle(hChildStdOutput_Rd); + return 0; }