Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space INSDEVEL and version 7.5.2

In this section:

Table of Contents
maxLevel1
minLevel1

Overview

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

Excerpt

Scroll Table Layout
sortDirectionASC
repeatTableHeadersdefault
widths10%,60%,10%,10%,10%
sortByColumn1
sortEnabledfalse
cellHighlightingtrue

CodeDescriptionEnabledReportedPlatform
FREE_LOCAL

Freeing null pointer

(tick)RuntimeWindows/Unix


Problem

The following code attempts to free a null pointer:

Code Block
languagecpp
themeEclipse
linenumberstrue
/*
 *File: freenull.c
 */
char*a;

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

Diagnosis at Runtime

Code Block
languagetext
linenumberstrue
[freelocl.c:8] **FREE_LOCAL**
>>		free(a);
Freeing null pointer: a
Stack trace where the error occurred
		main() freenull.c8
**Memory corrupted. Program may crash!!**
  • Line 2: Source file and line at which the problem was detected.
  • Line 3: Description of the problem and the expression that is in error.
  • Line 5: Stack trace showing the function call sequence leading to the error.
  • Line 6: Informational message indicating that a serious error has occurred which may cause the program to 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.