V726. An attempt to free memory containing the 'int A[10]' array by using the 'free(A)' function.


The analyzer has detected incorrect code, where an attempt is made to delete an array through the free() or other similar function while no corresponding special functions, such as malloc(), have been used to allocate the memory for this array. This issue leads to undefined behavior.

For example:

class A
{
  int x;
  int a[50];
  public:
    A(){}
    ~A(){ free(a); }
};

Since the memory hasn't been allocated in any special way, it shouldn't be freed by calling special functions either as it will be freed automatically once the object is destroyed. Therefore, the correct code should look like this:

class A
{
  int x;
  int a[50];
  public:
    A(){}
    ~A(){}
};

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-761.

You can look at examples of errors detected by the V726 diagnostic.


Bugs Found

Checked Projects
334
Collected Errors
12 668