Page tree

Skip to end of metadata
Go to start of metadata

In this section:

Overview

This error is generated if the address of a local variable is passed to free.

CodeDescriptionEnabledReportedPlatform
FREE_LOCAL

Freeing local memory

(tick)RuntimeWindows/Unix


Problem

The following code attempts to free a local variable that was not dynamically allocated.

/*
 * File: freelocl.c
 */
 main()
{
	char b, *a;

	a = &b;
	free(a);
	return (0);
}

Diagnosis at Runtime

[freelocl.c:9] **FREE_LOCAL**
>>			 free(a);
Freeing local memory: a
Pointer			 : 0xf7fffb0f
In block		 : 0xf7fffb0f thru 0xf7fffb0f (1 byte)
					b,declared at freelocl.c, 6
Stack trace where the error occurred:
			main() freelocl.c, 9
**Memory corrupted. Program may crash!!**
  • Line 2: Source line at which the problem was detected.
  • Line 3: Description of the problem and the expression that is in error.
  • Line 4: Value of the pointer that is being deallocated.
  • Line 6: Information about the block of memory addressed by this pointer, including information about where this block was declared.
  • Line 7: Stack trace showing the function call sequence leading to the error.
  • Line 9: Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

Some systems allow this operation since they keep track of which blocks of memory are actually dynamically allocated, but this is not portable programming practice and is not recommended.

In most cases, this error will result from a simple coding mistake at the indicated source line which can be quickly corrected.

If your application is unable to distinguish between local variables and dynamically allocated memory blocks, you can suppress error messages by suppressing FREE_LOCAL in the Suppressions Control Panel.

  • No labels