From 7e431b947986d333e2405a232fb2ebe0d415dd43 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Thu, 3 Oct 2024 06:07:45 -0700 Subject: [PATCH] Catch possible exceptions in ~Agent Fixes warning: deps\winpty\src\agent\Agent.cc(231): warning C4722: 'Agent::~Agent': destructor never returns, potential memory leak --- deps/winpty/src/agent/Agent.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/deps/winpty/src/agent/Agent.cc b/deps/winpty/src/agent/Agent.cc index a77b6442c..9267b82a9 100644 --- a/deps/winpty/src/agent/Agent.cc +++ b/deps/winpty/src/agent/Agent.cc @@ -223,10 +223,18 @@ Agent::Agent(LPCWSTR controlPipeName, Agent::~Agent() { - trace("Agent::~Agent entered"); - agentShutdown(); - if (m_childProcess != NULL) { - CloseHandle(m_childProcess); + trace("Agent::~Aent entered"); + try { + agentShutdown(); + if (m_childProcess != NULL) { + CloseHandle(m_childProcess); + } + } catch (const std::exception &e) { + // Log the exception or handle it as needed + trace("Exception in Agent::~Agent: %s", e.what()); + } catch (...) { + // Catch any other types of exceptions + trace("Unknown exception in Agent::~Agent"); } }