In this section:

Overview

This error is generated when an attempt is made to de-allocate memory by using a pointer which currently points into the middle of a block, rather than to its beginning.

CodeDescriptionEnabledReportedPlatform
FREE_BODY

Freeing memory block from body

(tick)RuntimeWindows/Unix


Problem

The following code attempts to free a memory region using an invalid pointer.

/*
 * File: freebody.c
 */
 #include <stdlib.h>

main()
{
	char *a = (char *)malloc(10);
	free(a+1);
}

Diagnosis at Runtime

[freebody.c:9] **FREE_BODY**
>>	 	free(a+1);
Freeing memory block from body: a + 1

---- Associated Common Weakness Enumerations ----
CWE-763: Release of invalid pointer or reference
CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
CWE-761: Free of pointer not at start of buffer

Pointer		: 0x000173e9
Stack trace where the error occurred:
			main() freebody.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 5-8: CWEs associated with this problem.
  • Line 10: Value of the pointer that is being deallocated.
  • Line 11: Stack trace showing the function call sequence leading to the error.
  • Line 13: Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

This is normally a serious error. In most cases, the line number indicated in the diagnostics will have a simple error that can be corrected.

References

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

CWEDescription
CWE-763Release of invalid pointer or reference
CWE-119Improper Restriction of Operations within the Bounds of a Memory Buffer
CWE-761Free of pointer not at start of buffer
  • No labels