Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - FREE_GLOBAL



FREE_GLOBAL

Freeing global memory

This error is generated if the address of a global variable is passed to a routine that de-allocates memory.

Problem

The following code attempts to deallocate a global variable that was not dynamically allocated.


	1:	/*
	2:	 * File: freeglob.c
	3:	 */
	4:	char a[10];
	5:	
	6:	main()
	7:	{
	8:		free(a); bug
	9:		return (0);
	10:	}

Diagnosis (at runtime)


	[freeglob.c:8] **FREE_GLOBAL**
1.	>> 		free(a);
	
2.		Freeing global memory: a
	
3.		Pointer	   : 0x00012210
		In block   : 0x00012210 thru 0x00012217 (8 bytes)
4.			 	a,declared at freeglob.c, 4

		Stack trace where the error occurred:
5.				 main() freeglob.c, 8
	
6.		**Memory corrupted. Program may crash!!**


  1. Source line at which the problem was detected.
  2. Description of the problem and the expression that is in error.
  3. Value of the pointer that is being deallocated.
  4. Information about the block of memory addressed by this pointer, including information about where this block was declared.
  5. Stack trace showing the function call sequence leading to the error.
  6. 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 some cases, this error will result from a simple coding mistake at the indicated source line which can be quickly corrected.

A more complex problem may arise when a program uses both statically and dynamically allocated blocks in the same way. A common example is a linked list in which the head of the list is static, while the other entries are allocated dynamically. In this case, you must take care not to free the static list head when removing entries.

If your application is unable to distinguish between global and dynamically allocated memory blocks, you can suppress error messages by adding the option

	insure++.suppress FREE_GLOBAL

to the .psrc file.


< FREE_DANGLING > FREE_LOCAL
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft