Go to main content
Oracle® Developer Studio 12.6: Code Analyzer User's Guide

Exit Print View

Updated: June 2017

Dynamic Memory Access Warnings

Dynamic memory access checking finds the following types of warnings:

This section describes the possible causes of the warning and a code example of when the warning might occur.

Allocating Zero Size (AZS)


    #include <stdlib>
    int main()
      int *p = malloc(); // Allocating zero size memory block

Memory Leak (MLK)

Possible causes: Memory is allocated but not freed before exit or escaping from the function.


    int foo()
     int *p = (int*) malloc(sizeof(int));
     if (x) {
      p = (int *) malloc(5*sizeof(int));  // will cause a leak of the 1st malloc
    }                                     // The 2nd malloc leaked here

Speculative Memory Read (SMR)


    int i;
    if (foo(&i) != 0)  /* foo returns nonzero if it has initialized i */
    printf("5d\n", i);

The compiler might generate the following equivalent code for the above source:

    int i;
    int t1, t2'
    t1 = foo(&i);
    t2 = i; /* value in i is loaded. So even if t1 is 0, we have uninitialized read due to speculative load */
    if (t1 != 0) 
    printf("%d\n", t2);