← Back to Pull requests

[STF] Scope-guard batch 2: leak windows, wrong flavors, host-register UB #11224

Closed
unknown closed this pull request without merging on Sep 24, 2026 18:27 UTC
View on GitHub
unknown unknown commented on Sep 05, 2026 18:26 UTC
Author

Second PR of the scope-guard hardening campaign that began with #11187, from the same audit of all 148 SCOPE sites.

Real defects

  • 01-axpy-places.cu armed one guard after two 256 MB allocations, so a bad_alloc from the second leaked the first. Now one guard per resource, each armed immediately.

  • The scalar test fixture in stream_ctx.cuh freed a buffer that was still registered via cudaHostRegister when logical_data construction threw (freeing registered memory is undefined). A second guard declared after the registration unregisters before the earlier guard frees, relying on reverse-order execution.

  • parallel_for left new args_t owned by nobody across calls that can throw. Rather than guard each window, the tuple is now held by a unique_ptr and release()d at each ownership handoff — to the ctx resource on the graph path, to the host callback on the stream path.
  • This also closes a leak the guard formulation left open. The graph path set its args_adopted flag before ctx.add_resource(), so a throw from add_resource() skipped the delete. That leaks rather than double-frees, because parallel_for_args_resource frees args only when its callback runs — its destructor does not — so a resource that never reaches the context never frees anything. Releasing only after add_resource() returns covers both throw sites, with no flag and no guard.

    Wrong flavors, now that a throwing guard body aborts with a report rather than terminating silently (#11187):

  • Three unit-test contexts finalized in SCOPE(exit). finalize() submits pending work and synchronizes, which is neither meaningful nor safe on a context being torn down by an exception.
  • Rebased onto #11226. The cfd.cu and pretty_print.cuh fixes from the original version of this PR are gone from the diff: they split a checked fclose into a SCOPE(success)/SCOPE(fail) pair, and #11226 has since collapsed that same pair into a single SCOPE(exit, failing). Main's version supersedes them.

    Not changed, deliberately: the device-restore guards in the places layer (cudaSetDevice(prev_dev) and the primary-context release). After #11187 a failure there aborts with a report, which is the right outcome, since continuing would run subsequent work on the wrong device.

    🤖 Generated with Claude Code

    Diff: 296 lines (+222 / -74) across 3 files Reviewer: andralex Review duration: 27361m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 296 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.341
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #11224"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%
    Repository