Bioplib
Protein Structure C Library
|
Safe malloc()/free() routines which check for array overflow on free. More...
Go to the source code of this file.
Data Structures | |
struct | _memlist |
Macros | |
#define | CHECKSIZE 256 /* Default protection buffer size */ |
#define | BLANK (char)(0xFF) /* Default blanking character */ |
#define | MAXBYTE 8 /* Max bytes occupied by an address */ |
Typedefs | |
typedef struct _memlist | MEMLIST |
Functions | |
void * | blSafemalloc (int nbytes) |
BOOL | blSafefree (void *ptr) |
void | blSafeleaks (void) |
Safe malloc()/free() routines which check for array overflow on free.
This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.
The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.
The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.
blSafemalloc() and blSafefree() are provided as temporary debugging replacements for malloc() and free(). They maintain their own linked list of malloc()'d memory and allocate a `protection buffer' each side of the requested amount of memory. This is filled with a given pattern and, when safefree() is called, this buffer is checked to ensure the pattern is still present.
Unlike free(), blSafefree() is of type BOOL, returning TRUE if an error occured.
The size of the buffer (default 256bytes each side) may be controlled by the environment variable SM_SIZE. If code continues to core dump, try increasing the value of SM_SIZE.
The byte used for filling the protection buffers (default 255) is defined by the environment variable SM_FILL. If code which core dumps with normal malloc()/free(), but not with blSafemalloc() / blSafefree(), yet no error message is generated, the character which is corrupting memory is probably the same as the fill character. Try modifying SM_FILL.
NOTE: safemem.h must be included after macros.h
Definition in file safemem.c.
#define BLANK (char)(0xFF) /* Default blanking character */ |
#define CHECKSIZE 256 /* Default protection buffer size */ |
BOOL blSafefree | ( | void * | ptr | ) |
void blSafeleaks | ( | void | ) |
void* blSafemalloc | ( | int | nbytes | ) |
[in] | nbytes | Number of bytes to allocate |
Debugging version of malloc() which creates protection buffers each side of the requested memory block.