free() — Free a block of storage

Format

#include <stdlib.h>

void free(void *ptr);

General description

The free() function frees a block of storage pointed to by ptr. The ptr variable points to a block previously reserved with a call to calloc(), malloc(), or realloc(). The number of bytes freed is the number of bytes specified when you reserved (or reallocated, in the case of realloc()), the block of storage. If ptr is NULL, free() simply returns without freeing anything. Since ptr is passed by value free() will not set ptr to NULL after freeing the memory to which it points.

Notes:
  1. Use of this function requires that an environment has been set up by using the __cinit() function. When the function is called, GPR 12 must contain the environment token created by the __cinit() call.
  2. Attempting to free a block of storage not allocated with calloc(), malloc(), or realloc(), or previously freed storage, can affect the subsequent reserving of storage and lead to an abend.

Returned value

free() returns no value.

Related Information