In this section:

Overview

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.

CodeDescriptionEnabledReportedPlatform
LEAK_RETURN

Memory leaked by ignoring returned value

(tick)RuntimeWindows/Unix


Problem

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

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

char *gimme()
{
	return <return>;
}

main()
{
	gimme();
	return (0);
}

Diagnosis at Runtime

[leakret.c:8] **LEAK_RETURN**
>>			 gimme();
Memory leaked ignoring return value: <return>
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
  • Line 2: Source file and line at which the problem was detected.
  • Line 3: Description of the problem and the block that is to be lost.
  • Line 4: 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, suppress LEAK_RETURN in the Suppressions Control Panel.

  • No labels