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.
This commit is contained in:
John L 2023-01-20 14:54:00 -08:00 коммит произвёл GitHub
Родитель 41e4e73cc1
Коммит 798f603084
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -80,7 +80,7 @@ Result<std::shared_ptr<WinHttpConnection>> WinHttpConnection::Initialize(
RETURN_HR_IF(E_INVALIDARG, !call);
http_stl_allocator<WinHttpConnection> a{};
auto connection = std::shared_ptr<WinHttpConnection>{ new (a.allocate(1)) WinHttpConnection(hSession, call, proxyType, std::move(securityInformation)), http_alloc_deleter<WinHttpConnection>() };
auto connection = std::shared_ptr<WinHttpConnection>{ new (a.allocate(1)) WinHttpConnection(hSession, call, proxyType, std::move(securityInformation)), http_alloc_deleter<WinHttpConnection>(), a };
RETURN_IF_FAILED(connection->Initialize());
return connection;

Просмотреть файл

@ -13,7 +13,7 @@ NAMESPACE_XBOX_HTTP_CLIENT_BEGIN
Result<std::shared_ptr<WinHttpProvider>> WinHttpProvider::Initialize()
{
http_stl_allocator<WinHttpProvider> a{};
auto provider = std::shared_ptr<WinHttpProvider>{ new (a.allocate(1)) WinHttpProvider, http_alloc_deleter<WinHttpProvider>() };
auto provider = std::shared_ptr<WinHttpProvider>{ new (a.allocate(1)) WinHttpProvider, http_alloc_deleter<WinHttpProvider>(), a };
RETURN_IF_FAILED(XTaskQueueCreate(XTaskQueueDispatchMode::Immediate, XTaskQueueDispatchMode::Immediate, &provider->m_immediateQueue));

Просмотреть файл

@ -129,7 +129,7 @@ Result<std::shared_ptr<WebSocket>> WebSocket::Initialize()
++httpSingleton->m_lastId,
httpSingleton->m_websocketPerform,
httpSingleton->m_performEnv.get()
}, http_alloc_deleter<WebSocket>{} };
}, http_alloc_deleter<WebSocket>{}, a };
return websocket;
}