Skip to content

Avoid confusing AIO callback lifetime test#13159

Merged
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-aio-callback-test-coverity
May 13, 2026
Merged

Avoid confusing AIO callback lifetime test#13159
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-aio-callback-test-coverity

Conversation

@bneradt
Copy link
Copy Markdown
Contributor

@bneradt bneradt commented May 13, 2026

Coverity reports the AIO callback lifetime regression test as a leak
and bad free because the test heap-allocates an owner object whose
member callback is destroyed indirectly during completion. The runtime
behavior is intentional, but the ownership pattern makes the regression
test look invalid to static analysis.

This updates the fixture so the owner has normal stack lifetime and
owns the callback through a unique_ptr. The completion handler still
destroys the callback before AIOCallback::io_complete() returns,
preserving the lifetime coverage while making the allocation and free
visible to analysis.

Coverity reports the AIO callback lifetime regression test as a leak
and bad free because the test heap-allocates an owner object whose
member callback is destroyed indirectly during completion. The runtime
behavior is intentional, but the ownership pattern makes the regression
test look invalid to static analysis.

This updates the fixture so the owner has normal stack lifetime and
owns the callback through a unique_ptr. The completion handler still
destroys the callback before AIOCallback::io_complete() returns,
preserving the lifetime coverage while making the allocation and free
visible to analysis.
@bneradt bneradt added this to the 11.0.0 milestone May 13, 2026
@bneradt bneradt self-assigned this May 13, 2026
@bneradt bneradt requested review from Copilot and zwoop May 13, 2026 17:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors an AIO callback regression test to use stack-allocated owner with a unique_ptr-managed callback, avoiding Coverity false positives about leaks/bad frees while preserving the lifetime test coverage.

Changes:

  • Replace heap-allocated AIOCompletionOwner with stack allocation
  • Wrap AIOCallback member in std::unique_ptr so it can be destroyed during completion
  • Update test name and assertions to reflect the new ownership model

auto *callback = owner.callback.get();

// Without ASan, a broken implementation can still pass because the stale value of from_ts_api is typically false.
CHECK(callback->io_complete(EVENT_NONE, nullptr) == EVENT_DONE);
Copy link
Copy Markdown
Contributor

@zwoop zwoop May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but after completing this, I think callback is in an undefined state. We don't use it after this, but maybe we should NULL it out or something ? In case someone looks at this after we retire.

@bneradt bneradt merged commit f0970ef into apache:master May 13, 2026
19 checks passed
@bneradt bneradt deleted the fix-aio-callback-test-coverity branch May 13, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants