>
>
>
V726. Attempt to free memory containing…


V726. 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(){}
};

This diagnostic is classified as:

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