C and C++ Binaries


ALLOC.LEAK : Leak

Summary

Dynamically allocated storage has not been freed.

Properties

Class Name Leak
Significance reliability
Mnemonic ALLOC.LEAK
Categories
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.
Availability Available for C and C++.
Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Leak"

Example

#include <stdlib.h>

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

Notes

A leak occurs when the last reference to a dynamically allocated object is lost.

Enforced Checks

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

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.