In this section:

Overview

This error is generated if the null pointer is passed to a routine that de-allocates memory.

CodeDescriptionEnabledReportedPlatform
FREE_NULL

Freeing null pointer

(tick)RuntimeWindows/Unix


Problem

The following code attempts to free a null pointer:

/*
 *File: freenull.c
 */
char*a;

main()
{
	free(a);
	return 0;
}

Diagnosis at Runtime

[freelocl.c:8] **FREE_LOCAL**
>>		free(a);
Freeing null pointer: a

---- Associated Common Weakness Enumerations ----
CWE-476: Null pointer dereference

Stack trace where the error occurred
		main() freenull.c8
**Memory corrupted. Program may crash!!**

Repair

The quick, simple solution is to add code to check whether the pointer is null before calling free(). Alternatively, check the stack trace. Doing so can lead to clues as to how the pointer was set to null in the first place, so that the error can be prevented from the root.

References

The table below shows Common Weakness Enumerations associated with this error.

CWEDescription
CWE-476Null pointer dereference