Skip to main content

IAR Embedded Workbench for RL78 5.20

LIB-return-leak

In this section:
Synopsis

The return values from one or more library functions were not stored, returned, or passed as a parameter.

Enabled by default

Yes

Severity/Certainty

High/High

highhigh.png
Full description

The return values from one or more library functions were not stored, returned, or passed as a parameter. If any of these functions return a pointer to newly allocated memory, and the return value is discarded, the memory is inaccessible and thus leaked. These functions are inspected: malloc(), calloc(), and realloc().

Coding standards
CERT MEM31-C

Free dynamically allocated memory exactly once

CWE 252

Unchecked Return Value

CWE 394

Unexpected Status Code or Return Value

Code examples

The following code example fails the check and will give a warning:

#include <stdlib.h>

void example(void) {
  malloc(1);  //the return value of malloc is not
              // stored
}

The following code example passes the check and will not give a warning about this issue:

#include <stdlib.h>

void example(void) {
  int* x = malloc(1);  // OK - the return value of
                       // malloc is being stored in x
}