C and C++ Binaries


ALLOC.LEAK : メモリリーク/リソースリーク

要旨

動的にメモリ割り当てされた領域が解放されていません。

プロパティ

クラス名 Leak
日本語クラス名 メモリリーク/リソースリーク
クラス分類 信頼性 (reliability)
ニーモニック ALLOC.LEAK
カテゴリー
MisraC2023 MisraC2023:22.1 All resources obtained dynamically by means of Standard Library functions shall be explicitly released
  MisraC2023:D.4.1 Run-time failures shall be minimized
Misra2012 Misra2012:22.1 All resources obtained dynamically by means of Standard Library functions shall be explicitly released
  Misra2012:D.4.1 Run-time failures shall be minimized
AUTOSARC++14 AUTOSARC++14:A18-5-5 Memory management functions shall ensure the following: (a) deterministic behavior resulting with the existence of worst-case execution time, (b) avoiding memory fragmentation, (c) avoid running out of memory, (d) avoiding mismatched allocations or deallocations, (e) no dependence on non-deterministic calls to kernel.
CWE CWE:401 Missing Release of Memory after Effective Lifetime
  CWE:459 Incomplete Cleanup
  CWE:771 Missing Reference to Active Allocated Resource
  CWE:772 Missing Release of Resource after Effective Lifetime
  CWE:773 Missing Reference to Active File Descriptor or Handle
  CWE:775 Missing Release of File Descriptor or Handle after Effective Lifetime
  CWE:1091 Use of Object without Invoking Destructor Method
TS17961 TS17961:5.18-fileclose 5.18. Failing to close files or free dynamic memory when they are no longer needed
CERT-C CERT-C:CON30-C Clean up thread-specific storage
  CERT-C:FIO42-C Close files when they are no longer needed
  CERT-C:MEM00-C Allocate and free memory in the same module, at the same level of abstraction
  CERT-C:MEM11-C Do not assume infinite heap space
  CERT-C:MEM31-C Free dynamically allocated memory when no longer needed
CERT-CPP CERT-CPP:ERR57-CPP Do not leak resources when handling exceptions
  CERT-CPP:FIO51-CPP Close files when they are no longer needed
  CERT-CPP:MEM51-CPP Properly deallocate dynamically allocated resources
  CERT-CPP:OOP54-CPP Gracefully handle self-copy assignment
JSF++ JSF++:79 All resources acquired by a class shall be released by the class's destructor.
  JSF++:81 The assignment operator shall handle self-assignment correctly.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Leak"

#include <stdlib.h>

int leak(void){
    int rv=0;
    char *p = malloc(100);
    if (p){
        rv = 1;
    }
    return rv;  /* 'Leak' warning issued here */
}

注釈

動的に割当てられたメモリへの最後の参照が失われた時に発生します。

強制的なチェック

CodeSonar checks for leaks of the values returned from any function treated as an allocator by CodeSonar:

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。