/* leakfinder.h - check for memory leaks
**
** Version 1.11 of 15Nov2022
**
**
** Copyright (C) 2022 by Jef Poskanzer <jef@mail.acme.com>.
** All rights reserved.
**
** You may use this software however you like as long as you keep my
** name on it and don't sue me.
**
** For commentary on this license please see http://acme.com/license.html
**
**
** This is a wrapper for C/Unix malloc() that helps you find memory
** leaks. There are lots of other tools to do this, such as valgrind
** and purify. The advantage of leakfinder is that it's tiny.
** 
** You do have to make some source code changes to use it, so it's
** not as convenient as the other tools.
** 
**   - Add leakfinder.[hc] to your source tree.
**   - #include "leakfinder.h"
**   - Change all your malloc()/calloc()/realloc()/strdup()/free() calls to
**     be upper-case, i.e. MALLOC()/CALLOC()/REALLOC()/STRDUP()/FREE(). The
**     arguments stay the same.
** 
** On exit, leakfinder will report any allocations that did not get freed.
** The report shows the source filename, the line number, and a count of
** how many unfreed allocations there were.
** 
** If you want to turn leakfinder off but leave it installed in case
** you want to use it again later, you can add the compiler flag
** -DNO_LEAKFINDER. When compiled with this flag, leakfinder does
** nothing and adds zero overhead.
*/

#ifndef NO_LEAKFINDER

#define MALLOC(size) leakfinder_malloc( size, __FILE__, __LINE__ )
#define CALLOC(number,size) leakfinder_calloc( number, size, __FILE__, __LINE__ )
#define REALLOC(ptr,size) leakfinder_realloc( ptr, size, __FILE__, __LINE__ )
#define STRDUP(str) leakfinder_strdup( str, __FILE__, __LINE__ )
#define FREE(ptr) leakfinder_free( ptr )

void* leakfinder_malloc( size_t size, char* file, int line );
void* leakfinder_calloc( size_t number, size_t size, char* file, int line );
void* leakfinder_realloc( void* ptr, size_t size, char* file, int line );
char* leakfinder_strdup( char* str, char* file, int line );
void leakfinder_free( void* ptr );

#else /* NO_LEAKFINDER */

#define MALLOC(size) malloc( size )
#define CALLOC(number,size) calloc( number, size )
#define REALLOC(ptr,size) realloc( ptr, size )
#define STRDUP(str) strdup( str )
#define FREE(ptr) free( ptr )

#endif /* NO_LEAKFINDER */
