Skip to content

Coverity: delete leaf RegressionSM instances when they complete - #13690

Merged
bryancall merged 1 commit into
apache:masterfrom
bryancall:coverity-tests-2-regressionsm-lifetime
Sep 17, 2026
Merged

bryancall merged 1 commit into
apache:masterfrom
bryancall:coverity-tests-2-regressionsm-lifetime

Conversation

@bryancall

Copy link
Copy Markdown
Contributor

One commit, three CIDs, one file. Separated from the rest of #13682 because it is the only change in that series that alters object lifetime in the cache regression machinery, and the only one no ctest case can exercise.

What leaks

REGRESSION_TEST(RegressionSM) builds a tree of RegressionSM nodes and calls top_sm->run(pstatus). Nothing is ever deleted, which is what CIDs 1022149, 1022150 and 1022151 report.

The ownership split matters:

  • Composite nodes already self-delete. The only two terminal exits from a composite's state machine both do it — RegressionSM::run() when nwaiting hits 0 after the child loop, and regression_sm_waiting() when nwaiting is 0 on the retry callback. Every other path either reschedules or re-enters run().
  • Leaf nodes never did. ReRegressionSM::run() calls done() synchronously and returns, so it never schedules and therefore never reaches regression_sm_waiting() — which is the only place that would have deleted it.

So 12 leaf instances leak per run: the 6 built by the test body, plus 6 more created internally by RegressionSM::run()'s repeat path (children[0]->clone() for ichild != n-1).

Deleting the tree from the test body would be a double-free. This is worth stating explicitly because it is the obvious-looking fix: a unique_ptr vector in the test body (attempted in 0690f09282, never merged) also cannot reach the internally-created clones.

Why self-delete is safe here

xrun() touches no members after run() returns; done() touches none after parent->child_done() returns; the child loop never re-reads the node after xrun(); and in the repeat path children[0] is only dereferenced for cloning on iterations 0..n-2 and handed over on the last, so it dies last. A parent always outlives its children, since its nwaiting only reaches 0 after every child's child_done().

This is the same contract CacheTestSM::complete() already uses in this subsystem (done(); delete this;), so the change makes the two leaf implementations consistent rather than introducing a new rule.

Verification status — please read before merging

RegressionSM is a REGRESSION_TEST compiled into inkcache and invoked via traffic_server -R. No ctest case exercises it, so this change is compile-verified and reasoned about but has not been executed. It wants an -R run.

For completeness: CIDs 1021840 and 1021841 (RegressionTest_cache, also resource leaks) are not addressed here, because nothing in that function leaks. The 12 CACHE_SM prototypes are stack objects that are only cloned, never run; the clones are leaves that self-delete via complete(); the composites self-delete as above. Those two are recommended for triage as false positives in #13682.

ReRegressionSM::run() completes synchronously and never reaches
regression_sm_waiting(), so nothing ever freed the six instances the
test builds or the six clones RegressionSM::run() makes for the repeat
counts. Composite nodes already delete themselves; leaves now follow
the same contract CacheTestSM::complete() uses.

Coverity CID 1022149, CID 1022150, CID 1022151.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The lifetime change is compile-verified but not exercised by a ctest case and requires human validation.

Pull request overview

Fixes leaks from synchronous leaf RegressionSM instances by deleting them after completion.

Changes:

  • Adds self-deletion to ReRegressionSM::run().
  • Preserves existing composite cleanup behavior.
File summaries
File Description
src/iocore/cache/RegressionSM.cc Deletes completed leaf state machines.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@JosiahWI JosiahWI added the Tests label Sep 15, 2026
@JosiahWI JosiahWI added this to the 11.0.0 milestone Sep 15, 2026
@bryancall
bryancall requested a review from JosiahWI September 17, 2026 02:02
@bryancall

Copy link
Copy Markdown
Contributor Author

@JosiahWI It is a test and a one liner.

@JosiahWI JosiahWI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change is an improvement.

@bryancall
bryancall merged commit 988c831 into apache:master Sep 17, 2026
14 checks passed
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