CWE-401¶
Missing Release of Memory after Effective Lifetime. [Improper-Control-Of-A-Resource-Through-Its-Lifetime]
Required inputs: IR, StaticSemanticAnalysis
Demonstrative Examples Functional Areas
Example 1
The following C function leaks a block of allocated memory if the call to read() does not return the expected number of bytes:
Example Language:C
char* getBlock(int fd) {
char* buf = (char*) malloc(BLOCK_SIZE);
if (!buf) {
return NULL;
}
if (read(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
return NULL;
}
return buf;
}
Demonstrative Examples Functional Areas
- Memory Management
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
memory_leak |
Call allocates leaking memory |
None |
False |
possible_memory_leak |
Call allocates possibly leaking memory |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
resources¶
resources : set[str] = {'C++ArrayHeapMemory', 'C++HeapMemory', 'HeapMemory'}
witness_paths¶
witness_paths : bool = True
witness_should_include_exception_handling¶
witness_should_include_exception_handling : bool = False