Intel® Inspector User Guide for Linux* OS

ID 767796
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Memory Leak

Occurs when a block of memory is allocated, never deallocated, and not reachable (there is no pointer available to deallocate the block).

ID

Code Location

Description

1

Allocation site

Represents the location and associated call stack from which the memory block was allocated.

NOTE:

Intel Inspector distinguishes among Memory leak, Memory not deallocated, and Memory growth problem types in the following manner:

  • Memory leak problems occur when a block of memory is allocated, never deallocated, and not reachable (there is no pointer available to deallocate the block). Severity level = (Error).

  • Memory not deallocated problems occur when a block of memory is allocated, never deallocated, but still reachable at application exit (there is a pointer available to deallocate the block). Severity level = (Warning).

  • Memory growth problems occur when a block of memory is allocated, but not deallocated, within a specific time segment during application execution. Severity level = (Warning).

C Example

char *pStr = (char*) malloc(512);
return;

Fortran Example

function LEAK
integer, pointer, dimension(:) :: ptr
integer LEAK(100)
integer :: val

allocate(ptr(100))
allocate(ptr(100))
allocate(ptr(100))
ptr(2)=val
val=ptr(1)
LEAK = ptr

end function LEAK

Possible Correction Strategies

Use the appropriate deallocation function to return the memory block to the heap after its last use.

Platform

Memory Allocator

Memory Deallocator

C++ language

new operator

delete operator

new[] operator

delete[] operator

C language

malloc(), calloc(), or realloc()functions

free() function

Fortran language

allocate() function

deallocate() function