Udostępnij za pośrednictwem


C6280

warning C6280: <variable> is allocated with <function>, but deleted with <function>

This warning indicates that the calling function has inconsistently allocated memory with a function from one memory allocation family and freed it with a function from another memory allocation family.

For example, this warning would be produced if memory is allocated with malloc but freed with GlobalFree or delete. Note that in the specific cases of mismatches between array new[] and scalar delete (or vice versa), more precise warnings are reported instead.

Example

The following sample code generates this warning:

#include <stdlib.h>
void f(int arraySize)
{
  int *pInt;
  
  pInt = (int *)calloc(arraySize, sizeof (int));
  // code ...
  delete pInt;
}

To correct this warning, use the following sample code:

#include <stdlib.h>
void f(int arraySize)
{
  int *pInt;
  
  pInt = (int *)calloc(arraySize, sizeof (int));
  // code ...
  free(pInt);
}

Different API definitions can use different heaps. For example, GlobalAlloc uses system heap, and free uses C heap. This defect is likely to cause memory corruptions and crashes.

See Also

Reference

calloc

malloc

free

operator new (<new>)

delete Operator (C++)