C6283

warning C6283: <variable> is allocated with array new [], but deleted with scalar delete

This warning appears only in C++ code and indicates that the calling function has inconsistently allocated memory with the array new [] operator, but freed it with the scalar delete operator. This defect might cause leaks, memory corruptions, and, in situations where operators have been overridden, crashes. If memory is allocated with array new [], it should typically be freed with array delete[].

Example

The following code generates this warning:

void f( )
{
  char *str = new char[50];
  // code ...
  delete str;
}

To correct this warning, use the following code:

void f( )
{
  char *str = new char[50];
  // code ...
  delete[] str;
}

Warning C6283 only applies to arrays of primitive types such as, integers or characters. If elements of the array are objects of class type then warning C6278 is issued.