Skip to content

DetourModKit v3.2.1

Choose a tag to compare

@tkhquang tkhquang released this 25 Apr 07:32
· 272 commits to main since this release
9d023e6

Release Title: Loader-Lock Leak Path Hardening
Version: 3.2.1

Changelog:
A focused hardening patch on top of v3.2.0. Aligns Logger::shutdown_internal and ~ConfigWatcher with the same new (std::nothrow) discipline that HookManager::~HookManager adopted in v3.2.0, so all three loader-lock leak paths now uphold the noexcept destructor contract honestly under OOM. No API changes, no behavior changes on the success path; nothing on the per-frame hot path moves.

  • What's new in v3.2.1

    • Honest noexcept under OOM in two more leak paths. Logger::shutdown_internal and ~ConfigWatcher previously appended their detached state to a static std::vector via emplace_back, which can throw std::bad_alloc and turn a noexcept destructor into std::terminate. Both paths now allocate a per-call heap cell via new (std::nothrow) and leak the cell, mirroring the discipline introduced for HookManager in v3.2.0. Issue #75.
    • Logger now pins the module on the leak path. Logger::shutdown_internal was missing the pin_current_module() call mandated by the project's leak-on-purpose discipline (AGENTS.md). Detached AsyncLogger writer threads can now safely outlive the destructor without risking unmapped code pages.
    • ~ConfigWatcher falls back gracefully on OOM. When the heap cell allocation itself fails, the destructor calls m_impl.release() to leak the raw Impl pointer without invoking ~Impl (which would tear down the detached StoppableWorker under loader lock). Strictly safer than the prior emplace_back path, which terminated the process via the noexcept guarantee on bad_alloc.
  • Why this is a patch release

    • No public API surface changes. Existing v3.2.0 callers compile and link unchanged.
    • The fix only takes effect when the destructor runs under the Windows loader lock (FreeLibrary from DllMain), which is the same scenario already covered in v3.2.0 for HookManager. Normal teardown paths are untouched.
    • Both pre-existing patterns were safe in practice (the branch fires at most once per instance during DLL unload, where an OOM-induced terminate is indistinguishable from OS teardown). The new code is "honest noexcept" cleanliness, not a bug fix in the everyday sense.
  • Tests

    • tests/test_logger.cpp and tests/test_config_watcher.cpp add file-scope static_assert guards on is_nothrow_move_constructible_v for the leak cell types, mirroring the is_nothrow_swappable_v pattern in tests/test_hook_manager.cpp. A future change that breaks the noexcept contract on std::shared_ptr<AsyncLogger> or default-deleter std::unique_ptr will fail to compile.
    • Existing ConfigWatcherLoaderLockTest.MultipleLoaderLockTeardownsAreSafe exercises the new per-call heap cell path (the test does not introspect the storage, so the new pattern slots in transparently).
    • Full suite green: 1028/1028 on mingw-debug, 231/231 critical filtered tests on msvc-debug.
  • Docs

    • AGENTS.md thread-safety table updated for Logger, ConfigWatcher, and HookManager rows to describe the per-call heap cell pattern instead of the static vector.
  • Backwards compatibility

    • All v3.2.0 APIs are unchanged. The fix is internal to two destructors.
    • No noexcept annotations changed. No header includes changed for consumers.

Full Changelog: v3.2.0...v3.2.1

Artifacts:
This release includes packages for different build environments. Both packages ensure library names are prefixed with lib for consistency (e.g., libDetourModKit.a, libDetourModKit.lib).

  • DetourModKit_MinGW_v3.2.1.zip: Built with MinGW (g++). Contains libDetourModKit.a, libsafetyhook.a, headers, CMake config files. (Zydis & Zycore are statically linked into libsafetyhook.a).
  • DetourModKit_MSVC_v3.2.1.zip: Built with MSVC (Visual Studio 2022). Contains libDetourModKit.lib, libsafetyhook.lib (or safetyhook.lib if SafetyHook doesn't get the prefix), headers, CMake config files. (Zydis & Zycore are statically linked into libsafetyhook.lib/safetyhook.lib).

These packages are ready to be used by other CMake projects via find_package(DetourModKit).
See README for detailed usage instructions.