Skip to content

Add regression test for QFuture awaiter destroyed before completion#317

Closed
Copilot wants to merge 7 commits into312-fix-qcorofuture-memory-leakfrom
copilot/sub-pr-316
Closed

Add regression test for QFuture awaiter destroyed before completion#317
Copilot wants to merge 7 commits into312-fix-qcorofuture-memory-leakfrom
copilot/sub-pr-316

Conversation

Copy link

Copilot AI commented Feb 1, 2026

PR #316 fixed a memory leak when a coroutine awaiting a QFuture is destroyed before the future completes. This PR adds a regression test for that scenario.

Test coverage

  • Awaiter lifecycle test (testAwaiterDestroyedBeforeFutureFinishes): Creates a QFuture, starts a coroutine that co_awaits it, destroys the coroutine before the future completes, then completes the future. Verifies:
    • No crash or use-after-free when the QFutureWatcher signal fires on a destroyed coroutine
    • Continuation callback is never invoked (confirming proper cleanup)

The test exercises the fix where QFutureWatcher is parented to the awaiter's dummy QObject, ensuring cleanup when the awaiter is destroyed.

// QPromise controls when the future completes
QPromise<int> promise;
promise.start();

{
    // Coroutine co_awaits the future, creating the awaiter
    auto continuation = [](QFuture<int> f) -> QCoro::Task<int> {
        co_return co_await f;  // WaitForFinishedOperationBase created here
    }(promise.future()).then([&](int) { /* ... */ });
    
    // Awaiter destroyed here when continuation goes out of scope
}

// Future completed after awaiter destruction - no crash
promise.addResult(42);
promise.finish();

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 5 commits February 1, 2026 20:49
Co-authored-by: danvratil <932001+danvratil@users.noreply.github.com>
Co-authored-by: danvratil <932001+danvratil@users.noreply.github.com>
Co-authored-by: danvratil <932001+danvratil@users.noreply.github.com>
Co-authored-by: danvratil <932001+danvratil@users.noreply.github.com>
Co-authored-by: danvratil <932001+danvratil@users.noreply.github.com>
@danvratil danvratil force-pushed the 312-fix-qcorofuture-memory-leak branch from f9284bb to a23a64f Compare February 1, 2026 20:55
Copilot AI changed the title [WIP] Fix review comments on memory leak fix in QFuture coro wrapper Add regression test for QFuture awaiter destroyed before completion Feb 1, 2026
Copilot AI requested a review from danvratil February 1, 2026 20:55
@danvratil danvratil closed this Feb 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants