User Guide

  • 2020
  • 10/21/2020
  • Public Content
Contents

Invalid Memory Access

Occurs when a read or write instruction references memory that is logically or physically invalid.
Problem type: Invalid memory access (Read)
Problem type: Invalid memory access (Write)
ID
Code Location
Description
1
Allocation site
If present, represents the location and associated call stack from which the memory block containing the offending address was allocated.
2
Deallocation site
If present, represents the location and associated call stack from which the memory block containing the offending address was deallocated.
The deallocation makes the access to the offending memory address logically invalid.
3
Read or Write
Represents the instruction and associated call stack responsible for the invalid access.
If no allocation or deallocation is associated with this problem, the memory address might be one of the following:
  • Logically invalid stack space (below the current stack pointer value)
  • Memory that is physically not allocated to the process
  • Memory that has been deallocated
The offset, if shown in the
Code Locations
pane, represents the byte offset into the allocated buffer where the
Invalid memory access
occurred.
C Examples
Heap example:
char *pStr = (char*) malloc(20); free(pStr); strcpy(pStr, "my string"); // Invalid write to deallocated memory
Stack example (set
Analyze stack accesses
to Yes when you configure the analysis):
void stackUnderrun() {    char array[10];    strcpy(array, "my string");    int len = strlen(array) - 1;    while (array[len] != 'Z') // Will read memory outside of array     len--; }
Fortran Example
integer, allocatable :: i, b(:) allocate( b(100)) ! Body of Console1 do i = 1, 100 b(i) = i end do deallocate(b) ! Invalid write to deallocated memory b(1) = 1
Possible Correction Strategies
If
Do This
An invalid pointer dereference (corrupt or invalid value) occurs.
This is usually a logic error in a sequential algorithm.
For example, the pointer may increment past the end or decrement before the beginning of dynamically allocated memory. This pointer address value can be the address of memory that is marked invalid to access.
When dereferencing a pointer, ensure:
  • The pointer refers to a valid object.
  • Pointer arithmetic stays within the bounds of the dynamically allocated memory.
A stale reference to memory occurs.
You can easily recognize this situation if allocation and deallocation information is present.
For example, if a thread holds a pointer to the heap, and another thread releases the memory back to the heap, then all future accesses to this memory are invalid.
You need a clear concept of object ownership to ensure one thread does not mistakenly release an object back to the heap while another thread considers the pointer valid. Consider reference counting.
The
Intel Inspector
detects an invalid memory access when enhanced dangling pointer check is disabled.
Run another memory error analysis with enhanced dangling pointer check enabled to potentially report allocation and deallocation information.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804