The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Macros | Functions
safemem.h File Reference

Safe malloc()/free() routines which check for array overflow on free. More...

#include "SysDefs.h"
#include "deprecated.h"

Go to the source code of this file.

Macros

#define _SAFEMEM_H_DEPRECATED
 
#define INIT(x, y)
 
#define INITPREV(x, y)
 
#define ALLOCNEXT(x, y)
 
#define ALLOCNEXTPREV(x, y)
 
#define FREELIST(y, z)
 
#define ORDFREELIST(y, z)
 
#define DELETE(x, y, z)
 
#define SAFEINIT(x, y)   INIT(x,y)
 
#define SAFEINITPREV(x, y)   INITPREV(x,y)
 
#define SAFEALLOCNEXT(x, y)   ALLOCNEXT(x,y)
 
#define SAFEALLOCNEXTPREV(x, y)   ALLOCNEXTPREV(x,y)
 
#define SAFEFREELIST(y, z)   FREELIST(y,z)
 
#define SAFEDELETE(x, y, z)   DELETE(x, y, z)
 

Functions

void * blSafemalloc (int nbytes)
 
BOOL blSafefree (void *ptr)
 
void blSafeleaks (void)
 

Detailed Description

Safe malloc()/free() routines which check for array overflow on free.

Version
V1.4
Date
14.08.14
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

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.

Description:

Usage:

N.B. This header file should be included after macros.h

Revision History:

Definition in file safemem.h.

Macro Definition Documentation

#define _SAFEMEM_H_DEPRECATED

Definition at line 75 of file safemem.h.

#define ALLOCNEXT (   x,
 
)
Value:
do { (x)->next=(y *)blSafemalloc(sizeof(y)); \
if((x)->next != NULL) { (x)->next->next=NULL; } \
NEXT(x); } while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
#define NEXT(x)
Definition: macros.h:249
void * blSafemalloc(int nbytes)
Definition: safemem.c:145

Definition at line 97 of file safemem.h.

#define ALLOCNEXTPREV (   x,
 
)
Value:
do { (x)->next=(y *)blSafemalloc(sizeof(y)); \
if((x)->next != NULL) \
{ (x)->next->prev = (x); \
(x)->next->next=NULL; } \
NEXT(x);} while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
struct _memlist * prev
Definition: safemem.c:115
#define NEXT(x)
Definition: macros.h:249
void * blSafemalloc(int nbytes)
Definition: safemem.c:145

Definition at line 100 of file safemem.h.

#define DELETE (   x,
  y,
 
)

Definition at line 132 of file safemem.h.

#define FREELIST (   y,
 
)
Value:
while((y)!=NULL) \
{ z *_freelist_macro_q; \
_freelist_macro_q = (y)->next; \
blSafefree((char *)(y)); \
(y) = _freelist_macro_q; \
}
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
BOOL blSafefree(void *ptr)
Definition: safemem.c:246

Definition at line 109 of file safemem.h.

#define INIT (   x,
 
)
Value:
do { x=(y *)blSafemalloc(sizeof(y)); \
if(x != NULL) x->next = NULL; } while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
void * blSafemalloc(int nbytes)
Definition: safemem.c:145

Definition at line 92 of file safemem.h.

#define INITPREV (   x,
 
)
Value:
do { x=(y *)blSafemalloc(sizeof(y)); \
if(x != NULL) {x->next = NULL; x->prev = NULL;} } \
while(0)
#define NULL
Definition: array2.c:99
void * blSafemalloc(int nbytes)
Definition: safemem.c:145

Definition at line 94 of file safemem.h.

#define ORDFREELIST (   y,
 
)
Value:
while((y)!=NULL) \
{ z *_freelist_macro_q; \
_freelist_macro_q = (y)->next; \
free((char *)(y)); \
(y) = _freelist_macro_q; \
}
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99

Definition at line 115 of file safemem.h.

#define SAFEALLOCNEXT (   x,
 
)    ALLOCNEXT(x,y)

Definition at line 168 of file safemem.h.

#define SAFEALLOCNEXTPREV (   x,
 
)    ALLOCNEXTPREV(x,y)

Definition at line 169 of file safemem.h.

#define SAFEDELETE (   x,
  y,
 
)    DELETE(x, y, z)

Definition at line 171 of file safemem.h.

#define SAFEFREELIST (   y,
 
)    FREELIST(y,z)

Definition at line 170 of file safemem.h.

#define SAFEINIT (   x,
 
)    INIT(x,y)

Definition at line 166 of file safemem.h.

#define SAFEINITPREV (   x,
 
)    INITPREV(x,y)

Definition at line 167 of file safemem.h.

Function Documentation

BOOL blSafefree ( void *  ptr)

Debugging version of free() which checks protection buffers each side of the requested memory block.

  • 23.06.95 Original By: ACRM
  • 27.02.98 Added cast to ptr
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 246 of file safemem.c.

void blSafeleaks ( void  )

Prints a list of any safemalloc()'d memory which was not freed

  • 03.07.06 Original By: ACRM
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 322 of file safemem.c.

void* blSafemalloc ( int  nbytes)
Parameters
[in]nbytesNumber of bytes to allocate
Returns
Pointer to block of memory

Debugging version of malloc() which creates protection buffers each side of the requested memory block.

  • 23.06.95 Original By: ACRM
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 145 of file safemem.c.