CWE-773

Missing Reference to Active File Descriptor or Handle. [Improper-Control-Of-A-Resource-Through-Its-Lifetime]

Required inputs: IR, StaticSemanticAnalysis

The product does not properly maintain references to a file descriptor or handle, which prevents that file descriptor/handle from being reclaimed. This can cause the product to consume all available file descriptors or handles, which can prevent other processes from performing critical file processing operations.Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

fd_multiple_deallocated

Possible multiple ‘{}’ calls to file descriptor.

None

False

fd_open_reference_lost

Reference to active file descriptor created by ‘{}’ lost.

None

False

memory_leak

Call allocates leaking memory

None

False

possible_memory_leak

Call allocates possibly leaking memory

None

False

Options

allocators

allocators

Type: set[bauhaus.analysis.config.QualifiedName]

Default: {'_creat', '_dup', '_dup2', '_open', '_wcreat', '_wopen', 'creat', 'dup', 'dup2', 'dup3', 'open', 'openat', 'openat2'}

Set of functions returning a new file descriptor.
 

deallocators

deallocators : set[bauhaus.analysis.config.QualifiedName] = {'_close', 'close'}

Set of functions closing a file descriptor.
 

resources

resources : set[str] = {'FileHandle'}

Set of resources to be checked (selection of rules in the Resources group).
 

test_open_filedescriptor_double_closed

test_open_filedescriptor_double_closed : bool = False

Perform search for multiple close calls on an open file destriptor.
 

test_open_filedescriptor_reference_lost

test_open_filedescriptor_reference_lost : bool = True

Perform search for a missing reference of an open file destriptor.
 

witness_paths

witness_paths : bool = True

Whether witness paths should be determined and included in the issue.
 

witness_should_include_exception_handling

witness_should_include_exception_handling : bool = False

Whether to only accept witness paths that include some kind of exception handling.