# 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](https://docs.swift-analyzer.com/get-started/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](https://docs.swift-analyzer.com/concepts/validation/) explains the evidence boundary. [Foundations](https://docs.swift-analyzer.com/concepts/foundations/) separates method assumptions from implementation claims.


---

Language: en
Canonical: https://docs.swift-analyzer.com/catalog/lifetime.undischarged-resource-obligation/
Product revision: 524fa07e0ae4153c84ac12ae9eb6559df89ec2be
Catalog revision: 4558458d
Documentation digest: 1f17ba58ab08627e0de898f1442067b09e960b48cd5605d6529e9275f8930d68
Channel: pre-prod; maturity: experimental; access: owner-provided checkout.
