NAME

liblkrs - Detect memory allocation errors.


SYNOPSIS

#include <lkr.h>

void *lkr_malloc(size_t size, char *fname, unsigned long lineno)

void *lkr_calloc(size_t nmemb, size_t size, char *fname, unsigned long lineno)

void *lkr_realloc(void *ptr, size_t size, char *fname, unsigned long lineno)

char *lkr_strdup(const char *src, char *fname, unsigned long lineno)

void lkr_free(void *ptr, char *fname, unsigned long lineno)

FILE *lkr_fopen(char *path, char *mode, char *fname, unsigned long lineno)

FILE *lkr_fdopen(int filedes, char *mode, char *fname, unsigned long lineno)

int lkr_fclose(FILE *stream, char *fname, unsigned long lineno)


DESCRIPTION

To use liblkrs, include lkr.h in any C source file you wish to debug. liblkrs works by using macros to replace calls in your code with calls to one of the lkr_*() functions listed above, so including lkr.h may be all you need to do. If you are using functions that liblkrs doesn't know about, you may want to write your own macros to wrap calls to those functions, for instance if you're using GNU readline, this might be useful:

 #define readline(a) lkr_register(readline(a), __FILE__, __LINE__)

Once you've recompiled your code, run it as usual, and use leakers to examine the trace file liblkrs wrote.


FUNCTIONS


void *lkr_register(void *ptr, char *filename, unsigned long linenum)

Register memory as allocated and return it. Useful when libraries you are linking against such as Readline allocates memory for you.

ptr: the newly allocated memory. filename: name of file where lkr_register() memory was allocated (__FILE__). linenum: line number where memory was allocated (__LINE__).

Returns: the return value is ptr.


void *lkr_unregister(void *ptr, char *fname, unsigned long lineno)

Unregister memory. Useful when you are passing memory you have registered (using malloc/calloc/realloc or lkr_register) off to another library to deallocate for you.

ptr: pointer to the memory you are about to deallocate. fname: filename where memory is being deallocated. lineno: line number where memory is being deallocated.

Returns: the return value is ptr.


void lkr_setflags(unsigned int flags)

Set the error handling flags. Use this to cause liblkrs to print a warning message to standard error or to dump core when an error is detected. Default is LKR_IGNORE.

flags: one of LKR_IGNORE, LKR_CROAK, or LKR_WARN


void lkr_setlogfile(const char *fname)

Use this function to change the log file name from the default filename: LEAKER_LOG. The environment variable LEAKER_LOG can be used to set this also.


AUTHOR

gabriel m. deal, gmd@yellowleaf.org, http://www.yellowleaf.org/gmd/software/leakers/