(no commit message)
[geda-pcb/pcjc2.git] / src / free_atexit.h
blobfb53b51ca6a1654684dcd7b50f06f85a37727e4c
1 /* This tiny library is to assist cleaning up harmless memory leaks caused
2 by (growing) buffers allocated in static variables in functions. The
3 library provides leaky_ prefixed variants of the common allocation
4 routines. These wrappers will remember all pointers they return and
5 can free all memory used, at the end of the applocation.
6 */
8 #include <stdlib.h>
10 #ifdef NDEBUG
11 #define leaky_init()
12 #define leaky_uninit()
13 #define leaky_malloc(size) malloc(size)
14 #define leaky_calloc(nmemb, size) calloc(nmemb, size)
15 #define leaky_realloc(old_memory, size) realloc(old_memory, size)
16 #else
18 /* set up atexit() hook - can be avoided if leaky_uninit() is called by hand */
19 void leaky_init (void);
21 /* free all allocations */
22 void leaky_uninit (void);
24 /* allocate memory, remember the pointer and free it after exit from the application */
25 void *leaky_malloc (size_t size);
27 /* same as leaky_malloc but this one wraps calloc() */
28 void *leaky_calloc (size_t nmemb, size_t size);
30 /* reallocate memory, remember the new pointer and free it after exit from the application */
31 void *leaky_realloc (void* old_memory, size_t size);
34 #endif