{"schemaVersion":"2.0.0","locale":"en","title":"Cleanup obligation is not discharged","description":"Rule ID: lifetime.undischarged-resource-obligation@1.0.0. Availability below refers to source-scan at product 524fa07e.","htmlUrl":"https://docs.swift-analyzer.com/catalog/lifetime.undischarged-resource-obligation/","markdownUrl":"https://docs.swift-analyzer.com/catalog/lifetime.undischarged-resource-obligation/index.md","productRevision":"524fa07e0ae4153c84ac12ae9eb6559df89ec2be","catalogRevision":"4558458d","docsRevision":"1f17ba58ab08627e0de898f1442067b09e960b48cd5605d6529e9275f8930d68","channel":"pre-prod","maturity":"experimental","access":"owner-provided-checkout","markdown":"# Cleanup obligation is not discharged\n\nRule ID: lifetime.undischarged-resource-obligation@1.0.0. Availability below refers to source-scan at product 524fa07e.\n\n## V-LIFE-09 — Cleanup obligation is not discharged\n\nCleanup obligation is not discharged. It examines ownership, resource state, and lifetime obligations across program paths.\n\n### Availability\n\nOpt in with --include-stdio-rules in source-scan. Selection does not mean a supported observation exists in your program.\n\nUse 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.\n\n```text\n\"$ANALYZER\" source-scan --package-path <package> --product <product> --allow-build --include-stdio-rules\n```\n\n### Example and action\n\nIllustrative 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.\n\n```swift\nimport Darwin\nfunc writeSample(to path: String) {\n    guard let file = fopen(path, \"w\") else { return }\n    fputs(\"sample\", file)\n}\n```\n\nThe 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.\n\n```swift\nimport Darwin\nfunc writeSample(to path: String) {\n    guard let file = fopen(path, \"w\") else { return }\n    defer { fclose(file) }\n    fputs(\"sample\", file)\n}\n```\n\n### Why this check works\n\nThe 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.\n\n### Assumptions and unknown\n\nThis 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.\n\n### Evidence and interpretation\n\nRead 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.\n\nHistorical evidence at 4558458d: recovery-required (historical qualification is incomplete and needs further evidence). That evidence has not been requalified for this product revision.\n\n[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.\n","anchors":["cleanup-obligation-is-not-discharged","V-LIFE-09","availability","example-and-action","why-this-check-works","assumptions-and-unknown","evidence-and-interpretation"]}
