Documentation menu

Back to matching rules

Cleanup obligation is not discharged

Rule ID: lifetime.undischarged-resource-obligation@1.0.0. Availability below refers to source-scan at product 524fa07e.

V-LIFE-09 — Cleanup obligation is not discharged#

Cleanup obligation is not discharged. It examines ownership, resource state, and lifetime obligations across program paths.

Availability#

Opt in with --include-stdio-rules in source-scan. Selection does not mean a supported observation exists in your program.

Use the terminal from Installation, with ANALYZER set. Replace <package> and <product> with your supported package path and product name.

text
"$ANALYZER" source-scan --package-path <package> --product <product> --allow-build --include-stdio-rules

Example and action#

Illustrative pattern only. This is not a complete runnable package or a reproduced source-scan result. Helper APIs and omitted context must be supplied by the application.

swift
import Darwin
func writeSample(to path: String) {
    guard let file = fopen(path, "w") else { return }
    fputs("sample", file)
}

The successful fopen creates a FILE resource whose owner must discharge the close obligation on every exit. Scope-bound cleanup is appropriate only while ownership remains here; do not add a second close after a transfer. A production writer must also handle write and close failures.

swift
import Darwin
func writeSample(to path: String) {
    guard let file = fopen(path, "w") else { return }
    defer { fclose(file) }
    fputs("sample", file)
}

Why this check works#

The opt-in stdio evaluator follows recognized resource creation, use and discharge events for the same owner/resource identity. An obligation that is not discharged on a supported path can supply a finding. This FILE illustration is not a replayed fixture and does not establish admission of every shown source form.

Assumptions and unknown#

This workflow is restricted to admitted stdio source forms. It does not establish arbitrary socket, Swift object, pointer or user-defined resource coverage. The tutorial selects this condition but contains no stdio observations; no stdio positive case is claimed from that run.

Evidence and interpretation#

Read condition coverage, observation counts and reasons in the actual report. A finding and an unknown observation can coexist. No observations is not a negative proof.

Historical evidence at 4558458d: recovery-required (historical qualification is incomplete and needs further evidence). That evidence has not been requalified for this product revision.

How we validate checks explains the evidence boundary. Foundations separates method assumptions from implementation claims.

Product 524fa07e · Historical catalog 4558458d
Experimental · Owner-provided checkout · Verified 2026-09-11

Read as MarkdownPage JSON

Report a documentation issue