@samitouri / QOSAMI-WSL / commits / 95150f21

Fix shared ptr circular reference leaks (#40480)

Co-authored-by: Copilot <copilot@github.com>

Feng Wang committed May 12, 2026 at 15:57 UTC 95150f212bd636a3f0cc26e947dead7772283c73
4 files changed +9 -9
src/windows/common/Dmesg.cpp
+4 -4
@@ -72,13 +72,13 @@ std::pair<std::wstring, std::thread> DmesgCollector::StartDmesgThread(InputSourc
72
73 THROW_LAST_ERROR_IF(!pipe);
74
75 - auto workerThread = std::thread([Self = shared_from_this(), Source, Pipe = std::move(pipe)]() {
75 + auto workerThread = std::thread([this, Source, Pipe = std::move(pipe)]() {
76 try
77 {
78 wsl::windows::common::wslutil::SetThreadDescription(L"Dmesg");
79
80 // When the pipe connects, start reading data.
81 - wsl::windows::common::helpers::ConnectPipe(Pipe.get(), INFINITE, Self->m_exitEvents);
81 + wsl::windows::common::helpers::ConnectPipe(Pipe.get(), INFINITE, m_exitEvents);
82
83 std::vector<char> buffer(LX_RELAY_BUFFER_SIZE);
84 const auto allBuffer = gsl::make_span(buffer);
@@ -89,7 +89,7 @@ std::pair<std::wstring, std::thread> DmesgCollector::StartDmesgThread(InputSourc
89 {
90 overlappedEvent.ResetEvent();
91 const auto bytesRead = wsl::windows::common::relay::InterruptableRead(
92 - Pipe.get(), gslhelpers::convert_span<gsl::byte>(allBuffer), Self->m_exitEvents, &overlapped);
92 + Pipe.get(), gslhelpers::convert_span<gsl::byte>(allBuffer), m_exitEvents, &overlapped);
93
94 if (bytesRead == 0)
95 {
@@ -97,7 +97,7 @@ std::pair<std::wstring, std::thread> DmesgCollector::StartDmesgThread(InputSourc
97 }
98
99 auto validBuffer = allBuffer.subspan(0, bytesRead);
100 - Self->ProcessInput(Source, validBuffer);
100 + ProcessInput(Source, validBuffer);
101 }
102 }
103 catch (...)
src/windows/common/Dmesg.h
+1 -1
@@ -17,7 +17,7 @@ Abstract:
17 #include "relay.hpp"
18 #include "RingBuffer.h"
19
20 -class DmesgCollector : public std::enable_shared_from_this<DmesgCollector>
20 +class DmesgCollector
21 {
22 public:
23 DmesgCollector() = delete;
src/windows/service/exe/GuestTelemetryLogger.cpp
+3 -3
@@ -52,13 +52,13 @@ void GuestTelemetryLogger::Start(const wil::unique_event& ExitEvent)
52 THROW_LAST_ERROR_IF(!pipe);
53
54 wil::unique_handle exitEvent(wsl::windows::common::wslutil::DuplicateHandle(ExitEvent.get()));
55 - m_thread = std::thread([Self = shared_from_this(), Pipe = std::move(pipe), ExitEvent = std::move(exitEvent)]() {
55 + m_thread = std::thread([this, Pipe = std::move(pipe), ExitEvent = std::move(exitEvent)]() {
56 try
57 {
58 wsl::windows::common::wslutil::SetThreadDescription(L"GuestTelemetryLogger");
59
60 // When the pipe connects, start reading data.
61 - const std::vector<HANDLE> exitEvents = {Self->m_threadExit.get(), ExitEvent.get()};
61 + const std::vector<HANDLE> exitEvents = {m_threadExit.get(), ExitEvent.get()};
62 wsl::windows::common::helpers::ConnectPipe(Pipe.get(), INFINITE, exitEvents);
63
64 std::vector<gsl::byte> buffer(LX_RELAY_BUFFER_SIZE);
@@ -76,7 +76,7 @@ void GuestTelemetryLogger::Start(const wil::unique_event& ExitEvent)
76 break;
77 }
78
79 - Self->ProcessInput(std::string_view{reinterpret_cast<const char*>(buffer.data()), bytesRead});
79 + ProcessInput(std::string_view{reinterpret_cast<const char*>(buffer.data()), bytesRead});
80 }
81 }
82 CATCH_LOG()
src/windows/service/exe/GuestTelemetryLogger.h
+1 -1
@@ -17,7 +17,7 @@ Abstract:
17 #include "RingBuffer.h"
18 #include "relay.hpp"
19
20 -class GuestTelemetryLogger : public std::enable_shared_from_this<GuestTelemetryLogger>
20 +class GuestTelemetryLogger
21 {
22 public:
23 GuestTelemetryLogger() = delete;