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 released.
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