MISRA C:2012 Rule 22.1
All resources obtained dynamically by means of Standard Library functions shall be explicitly released
描述
规则定义
All resources obtained dynamically by means of Standard Library functions shall be explicitly released 1 .
理由
资源是您在使用后必须归还给系统的物品。示例包括动态分配的内存和文件描述符。
如果您没有尽快显式释放资源,则可能会因资源耗尽而发生故障。
Polyspace 实现
检查项标记使用:
如果内存未释放,则会调用内存分配函数,如
malloc和aligned_alloc。如果文件未关闭,则执行文件打开函数,如
fopen。
您只能使用 Bug Finder 分析来检查此规则。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
| 组:资源 |
| 类别:必需 |
| AGC 类别:必需 |
版本历史记录
在 R2015b 中推出
另请参阅
MISRA C:2012 Dir
4.13 | MISRA C:2012 Rule
21.3 | MISRA C:2012 Rule
21.6 | Resource
leak | 检查 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.