void *CiTRMalloc(size_t size);
void *CiTRRealloc(void *ptr, size_t size);
void CiTRFree(void *ptr);
char *CiTRStrdup(const char *s);
On program exit, a report is given of memory space not freed. Other checks are made prior to frees that the space was allocated in the first place.
Other than this side effect the routines are compatible with the ANSI C standard library routines.
It is intended that for production running, these routines be #defined to the normal system routines by a simple change to citr_stdlib.h.
p1 = CiTRMalloc(12)
marker = p1
p2 = CiTRMalloc(10)
if (ERROR) CiTRRelease (marker)
Theory of operation:
When ever the user does a malloc, we ask for a little bit more. In this structure (which will be at the beginning of the buffer), we will store who they were, how much was asked for, and a reference back to an array of pointers to these malloced structures. The pointer we return to the user is a few bytes into the malloced buffer. When they do a free we follow this back reference to check that we haven't already freed this entry. This array is also dynamically allocated, but we will have a bit of garbage collection code for when the array is full. This will add a bit of complexity to the code when compaction occurs.
Release is a special routine to handle bail outs in complex routines that build deep OVc structures, and need to clean up after a failure
Report prints (on stdout) how much memory is still in use, and where it was malloced from. It will be set up as an exit handler.