From 798f60308444cbc86341361a924586abdf442438 Mon Sep 17 00:00:00 2001 From: John L Date: Fri, 20 Jan 2023 14:54:00 -0800 Subject: [PATCH] Fix a few unhooked allocations (#730) When creating a std::shared_ptr<> from a raw pointer, we need to pass in both a custom deleter and allocator. Though the object itself is already allocated, std::shared_ptr<> allocates some internal data on top of that. More details here: https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr. --- Source/HTTP/WinHttp/winhttp_connection.cpp | 2 +- Source/HTTP/WinHttp/winhttp_provider.cpp | 2 +- Source/WebSocket/hcwebsocket.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/HTTP/WinHttp/winhttp_connection.cpp b/Source/HTTP/WinHttp/winhttp_connection.cpp index cf4129ba..8fbe93f1 100644 --- a/Source/HTTP/WinHttp/winhttp_connection.cpp +++ b/Source/HTTP/WinHttp/winhttp_connection.cpp @@ -80,7 +80,7 @@ Result> WinHttpConnection::Initialize( RETURN_HR_IF(E_INVALIDARG, !call); http_stl_allocator a{}; - auto connection = std::shared_ptr{ new (a.allocate(1)) WinHttpConnection(hSession, call, proxyType, std::move(securityInformation)), http_alloc_deleter() }; + auto connection = std::shared_ptr{ new (a.allocate(1)) WinHttpConnection(hSession, call, proxyType, std::move(securityInformation)), http_alloc_deleter(), a }; RETURN_IF_FAILED(connection->Initialize()); return connection; diff --git a/Source/HTTP/WinHttp/winhttp_provider.cpp b/Source/HTTP/WinHttp/winhttp_provider.cpp index b8526f54..223d3b95 100644 --- a/Source/HTTP/WinHttp/winhttp_provider.cpp +++ b/Source/HTTP/WinHttp/winhttp_provider.cpp @@ -13,7 +13,7 @@ NAMESPACE_XBOX_HTTP_CLIENT_BEGIN Result> WinHttpProvider::Initialize() { http_stl_allocator a{}; - auto provider = std::shared_ptr{ new (a.allocate(1)) WinHttpProvider, http_alloc_deleter() }; + auto provider = std::shared_ptr{ new (a.allocate(1)) WinHttpProvider, http_alloc_deleter(), a }; RETURN_IF_FAILED(XTaskQueueCreate(XTaskQueueDispatchMode::Immediate, XTaskQueueDispatchMode::Immediate, &provider->m_immediateQueue)); diff --git a/Source/WebSocket/hcwebsocket.cpp b/Source/WebSocket/hcwebsocket.cpp index ddbbdefe..223f0711 100644 --- a/Source/WebSocket/hcwebsocket.cpp +++ b/Source/WebSocket/hcwebsocket.cpp @@ -129,7 +129,7 @@ Result> WebSocket::Initialize() ++httpSingleton->m_lastId, httpSingleton->m_websocketPerform, httpSingleton->m_performEnv.get() - }, http_alloc_deleter{} }; + }, http_alloc_deleter{}, a }; return websocket; }