1. Stephan Peijnik
  2. outofmemory_simulate



outofmemory_simulate is a small library intended to help
with simulating out of memory errors in applications.

The library is licensed under the terms of the GNU General Public License
(GPL) version 3, or later. See COPYING and the headers in all code files
for details.


In order to use outofmemory_simulate in your application you have to compile
outofmemory_simulate.c into your application and include outofmemory_simulate.h
in each and every file doing malloc()/realloc().

When including the header file make sure you define __OUTOFMEMORY_SIMULATE.
If you don't do outofmemory_simulate will not intercept malloc()/realloc()
calls at all.


  #include <stdio.h>
  #include <stdlib.h>

  #include "path/to/outofmemory_simulate.h"

After compiling outofmemory_simulate into your application and correctly
including the header file you can control when malloc()/realloc() will fail
using the _OUTOFMEMORY_SIMULATE_FAIL_ON (default) environment variable
when calling your program.

Please note that by default outofmemory_simulate will use printf() for
printing messages to stdout. You can disabled this behaviour by setting
the _OUTOFMEMORY_SIMULATE_NOPRINT (default) environment variable.