From cd8c5fc2eae4e8447b0a7836e0df648fcaeea162 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Sun, 25 Aug 2019 21:22:25 +0200 Subject: [PATCH] Fixed memory leak --- overlay_experimental/Base_Hook.cpp | 1 + overlay_experimental/DX10_Hook.cpp | 5 +++-- overlay_experimental/DX11_Hook.cpp | 5 +++-- overlay_experimental/DX12_Hook.cpp | 5 +++-- overlay_experimental/DX9_Hook.cpp | 5 +++-- overlay_experimental/OpenGL_Hook.cpp | 3 ++- overlay_experimental/Windows_Hook.cpp | 7 +++++-- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/overlay_experimental/Base_Hook.cpp b/overlay_experimental/Base_Hook.cpp index a7d3b88e..452309e6 100644 --- a/overlay_experimental/Base_Hook.cpp +++ b/overlay_experimental/Base_Hook.cpp @@ -12,6 +12,7 @@ #include Base_Hook::Base_Hook(): + _library(nullptr), _hooked(false) {} diff --git a/overlay_experimental/DX10_Hook.cpp b/overlay_experimental/DX10_Hook.cpp index ceba0e64..54e43b7b 100644 --- a/overlay_experimental/DX10_Hook.cpp +++ b/overlay_experimental/DX10_Hook.cpp @@ -12,6 +12,7 @@ DX10_Hook* DX10_Hook::_inst = nullptr; bool DX10_Hook::start_hook() { + bool res = true; if (!_hooked) { if (!Windows_Hook::Inst().start_hook()) @@ -63,12 +64,12 @@ bool DX10_Hook::start_hook() else { PRINT_DEBUG("Failed to hook DirectX 10\n"); - return false; + res = false; } if(pDevice)pDevice->Release(); if(pSwapChain)pSwapChain->Release(); } - return true; + return res; } void DX10_Hook::resetRenderState() diff --git a/overlay_experimental/DX11_Hook.cpp b/overlay_experimental/DX11_Hook.cpp index 5e5c1972..c27ede64 100644 --- a/overlay_experimental/DX11_Hook.cpp +++ b/overlay_experimental/DX11_Hook.cpp @@ -22,6 +22,7 @@ HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** bool DX11_Hook::start_hook() { + bool res = true; if (!_hooked) { if (!Windows_Hook::Inst().start_hook()) @@ -73,13 +74,13 @@ bool DX11_Hook::start_hook() else { PRINT_DEBUG("Failed to hook DirectX 11\n"); - return false; + res = false; } if(pDevice) pDevice->Release(); if(pSwapChain) pSwapChain->Release(); } - return true; + return res; } void DX11_Hook::resetRenderState() diff --git a/overlay_experimental/DX12_Hook.cpp b/overlay_experimental/DX12_Hook.cpp index edb85f8e..4b835baa 100644 --- a/overlay_experimental/DX12_Hook.cpp +++ b/overlay_experimental/DX12_Hook.cpp @@ -14,6 +14,7 @@ DX12_Hook* DX12_Hook::_inst = nullptr; bool DX12_Hook::start_hook() { + bool res = true; if (!_hooked) { if (!Windows_Hook::Inst().start_hook()) @@ -79,7 +80,7 @@ bool DX12_Hook::start_hook() else { PRINT_DEBUG("Failed to hook DirectX 12\n"); - return false; + res = false; } } } @@ -89,7 +90,7 @@ bool DX12_Hook::start_hook() if (pCommandQueue) pCommandQueue->Release(); if (pDevice) pDevice->Release(); } - return true; + return res; } void DX12_Hook::resetRenderState() diff --git a/overlay_experimental/DX9_Hook.cpp b/overlay_experimental/DX9_Hook.cpp index bbd5611a..1842493a 100644 --- a/overlay_experimental/DX9_Hook.cpp +++ b/overlay_experimental/DX9_Hook.cpp @@ -14,6 +14,7 @@ DX9_Hook* DX9_Hook::_inst = nullptr; bool DX9_Hook::start_hook() { + bool res = true; if (!_hooked) { if (!Windows_Hook::Inst().start_hook()) @@ -60,13 +61,13 @@ bool DX9_Hook::start_hook() else { PRINT_DEBUG("Failed to DirectX 9\n"); - return false; + res = false; } if(pDeviceEx)pDeviceEx->Release(); if(pD3D)pD3D->Release(); } - return true; + return res; } void DX9_Hook::resetRenderState() diff --git a/overlay_experimental/OpenGL_Hook.cpp b/overlay_experimental/OpenGL_Hook.cpp index ef707c06..de3071b7 100644 --- a/overlay_experimental/OpenGL_Hook.cpp +++ b/overlay_experimental/OpenGL_Hook.cpp @@ -16,6 +16,7 @@ OpenGL_Hook* OpenGL_Hook::_inst = nullptr; bool OpenGL_Hook::start_hook() { + bool res = true; if (!_hooked) { if (!Windows_Hook::Inst().start_hook()) @@ -46,7 +47,7 @@ bool OpenGL_Hook::start_hook() PRINT_DEBUG("Failed to hook OpenGL\n"); /* Problem: glewInit failed, something is seriously wrong. */ PRINT_DEBUG("Error: %s\n", glewGetErrorString(err)); - return false; + res = false; } } return true; diff --git a/overlay_experimental/Windows_Hook.cpp b/overlay_experimental/Windows_Hook.cpp index f755f343..4483a141 100644 --- a/overlay_experimental/Windows_Hook.cpp +++ b/overlay_experimental/Windows_Hook.cpp @@ -37,6 +37,7 @@ HWND GetGameWindow() bool Windows_Hook::start_hook() { + bool res = true; if (!_hooked) { GetRawInputBuffer = ::GetRawInputBuffer; @@ -51,7 +52,7 @@ bool Windows_Hook::start_hook() _hooked = true; } - return true; + return res; } void Windows_Hook::resetRenderState() @@ -171,7 +172,7 @@ Windows_Hook::Windows_Hook() : GetRawInputBuffer(nullptr), GetRawInputData(nullptr) { - + //_library = LoadLibrary(DLL_NAME); } Windows_Hook::~Windows_Hook() @@ -179,6 +180,8 @@ Windows_Hook::~Windows_Hook() PRINT_DEBUG("Windows Hook removed\n"); resetRenderState(); + + //FreeLibrary(reinterpret_cast(_library)); } Windows_Hook& Windows_Hook::Inst()