Skip to main content

Module resources

Module resources 

Source
Expand description

Resources Command - Resource Lifecycle Analysis

Analyzes resource lifecycle to detect leaks, double-close, and use-after-close issues.

§Analysis Types

  • R1: Resource detection - Identify resources requiring close
  • R2: Close verification - All-paths leak detection
  • R3: Double-close detection - Closing resources twice
  • R4: Use-after-close - Using closed resources
  • R6: Context manager suggestions - Suggest with statement
  • R7: Leak path enumeration - Detailed paths to leaks
  • R9: Constraint generation - LLM-ready constraints

§TIGER Mitigations

  • T04: MAX_PATHS=1000 with early termination for path enumeration

§Example

# Analyze a single file
tldr resources src/db.py

# Analyze specific function
tldr resources src/db.py query

# Check all issues
tldr resources src/db.py --check-all

# Show leak paths
tldr resources src/db.py --show-paths

Structs§

BasicBlock
A basic block in the simplified control flow graph.
DoubleCloseDetector
Double-close detector.
LeakDetector
Leak detector using CFG path analysis.
ResourceAnalysisResults
Aggregated resource analysis results for L2 consumption.
ResourceDetector
Resource detector for finding must-close resources.
ResourcesArgs
Analyze resource lifecycle to detect leaks, double-close, and use-after-close.
SimpleCfg
Simplified control flow graph for resource analysis.
UseAfterCloseDetector
Use-after-close detector.

Constants§

MAX_PATHS
Maximum paths to enumerate before early termination (TIGER-04).
RESOURCE_CLOSERS
Legacy constant for backward compatibility with tests
RESOURCE_CREATORS
Legacy constant for backward compatibility with tests

Functions§

analyze_source_for_resource_issues
Analyze source code for resource lifecycle issues.
build_cfg
Build a simplified CFG from a function AST.
build_cfg_multilang
Build a simplified CFG from a function AST, using language-specific patterns.
format_resources_text
Format resources report as human-readable text.
generate_constraints
Generate LLM-ready constraints from resource analysis.
run
Run the resources analysis command.
suggest_context_manager
Suggest context manager usage for resources.
suggest_context_manager_multilang
Suggest cleanup patterns using language-appropriate idioms.