Skip to content
Open
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
14 changes: 12 additions & 2 deletions Source/Windows.Test/Threading/CancellationMemoryLeakTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
//
// Including cancellation.h brings the no_destroy inline variable definition into
// this translation unit, so it is constructed during static initialization before
// main runs. We call _CrtDumpMemoryLeaks explicitly and return a non-zero exit
// code so that CTest treats the test as failed when leaks are detected.
// main runs. We also explicitly call add_listener on the none() token to verify
// that the early-out path (which returns a dummy ticket) does not trigger any
// heap allocations that would be reported as leaks.
//
// We call _CrtDumpMemoryLeaks explicitly and return a non-zero exit code so that
// CTest treats the test as failed when leaks are detected.

#include <crtdbg.h>
#include <cstdlib>
Expand All @@ -22,6 +26,12 @@
int main()
{
#ifdef _DEBUG
// Exercise the add_listener early-out path on cancellation::none().
// This should not allocate any memory since none() returns a dummy ticket.
{
auto ticket = arcana::cancellation::none().add_listener([] {});
}

// _CrtDumpMemoryLeaks reports all CRT debug-heap blocks still allocated.
if (_CrtDumpMemoryLeaks())
{
Expand Down