Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/dll/DetourTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@ extern "C" NTSYSCALLAPI NTSTATUS NTAPI NtGetNextThread(_In_ HANDLE ProcessHandle
DetourTransaction::DetourTransaction(const std::source_location aSource)
: m_source(aSource)
, m_state(State::Invalid)
, m_hasHeapLock(false)
{
spdlog::trace("Trying to start a detour transaction in '{}' ({}:{})", m_source.function_name(),
m_source.file_name(), m_source.line());

auto hasLock = HeapLock(GetProcessHeap());
if (!hasLock)
{
spdlog::error("Could not lock the process heap in '{}' ({}:{}). Last error: {}", m_source.function_name(),
m_source.file_name(), m_source.line(), GetLastError());
return;
}

m_hasHeapLock = true;

auto result = DetourTransactionBegin();
if (result == NO_ERROR)
{
Expand All @@ -45,6 +56,11 @@ DetourTransaction::~DetourTransaction()
{
Abort();
}

if (m_hasHeapLock)
{
HeapUnlock(GetProcessHeap());
}
}

const bool DetourTransaction::IsValid() const
Expand Down
1 change: 1 addition & 0 deletions src/dll/DetourTransaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ class DetourTransaction
const std::source_location m_source;
State m_state;
std::vector<wil::unique_handle> m_handles;
bool m_hasHeapLock;
};