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 - LEAK_RETURN



LEAK_RETURN

Memory leaked by ignoring returned value

This error is generated whenever a function returns a pointer to a block of memory which is then ignored by the calling routine. In this case, the allocated memory block is permanently lost and can never be freed.

Problem

This code calls the function gimme, which returns a memory block that is subsequently ignored by the main routine.

	1:	/*
	2:	 * File: leakret.c
	3:	 */
	4:	#include <stdlib.h>
	5:	
	6:	char *gimme()
	7:	{
	8:		return malloc(10);
	9:	}
	10:
	11:	main()
	12:	{
	13:		gimme(); bug
	14:		return (0);
	15:	}

Diagnosis (at runtime)

	[leakret.c:8] **LEAK_RETURN**
1.	>> 		gimme();
	
2.		Memory leaked ignoring return value: <return>
	
3.		Lost block:	0x000173e8 thru 0x000173f1 (10 bytes)
				block allocated at: 
				malloc()  (interface)
			 	 gimme()  leakret.c, 8
			  	  main()  leakret.c, 13

		Stack trace where the error occurred:
				  main() leakret.c, 13

  1. Source line at which the problem was detected.
  2. Description of the problem and the block that is to be lost.
  3. Description of the block of memory that is about to be lost, including its size and the line number at which it was allocated.

Repair

This problem usually results from an oversight on the part of the programmer, or a misunderstanding of the nature of the pointer returned by a routine. In particular, it is sometimes unclear whether the value returned points to a static block of memory, which will not need to be freed, or a dynamically allocated one, which should be.

Some applications may be unable to free memory blocks and may not need to worry about their permanent loss. To suppress these error messages in this case add the option

	insure++.suppress LEAK_RETURN

to the .psrc file.


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