MISRA C:2012 Rule 22.1
All resources obtained dynamically by means of Standard Library functions shall be explicitly released
Description
Rule Definition
All resources obtained dynamically by means of Standard Library functions shall be explicitly released1 .
Rationale
Resources are something that you must return to the system once you have used them. Examples include dynamically allocated memory and file descriptors.
If you do not release resources explicitly as soon as possible, then a failure can occur due to exhaustion of resources.
Polyspace Implementation
The checker flags uses of:
Memory-allocation functions such as
malloc
andaligned_alloc
if the memory is not released.File opening functions such as
fopen
if the file is not closed.
You can check for this rule with a Bug Finder analysis only.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Resources |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2015b
See Also
MISRA C:2012 Dir
4.13
| MISRA C:2012 Rule
21.3
| MISRA C:2012 Rule
21.6
| Resource
leak
| Check
MISRA C:2012 (-misra3)
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.