108 #define CHECKSIZE 256
109 #define BLANK (char)(0xFF)
126 static char sBlank =
BLANK;
162 if((envvar = getenv(
"SM_SIZE"))!=
NULL)
164 if(sscanf(envvar,
"%d",&sCheckSize))
168 sCheckSize = (1 + (int)(sCheckSize/MAXBYTE)) * MAXBYTE;
172 fprintf(stderr,
"Env. variable, SM_SIZE, is invalid.\n");
177 if((envvar = getenv(
"SM_FILL"))!=
NULL)
179 if(sscanf(envvar,
"%d",&PadValue))
182 fprintf(stderr,
"Env. variable, SM_FILL, has been \
183 shortened to the LSB.\n");
184 sBlank = PadValue%256;
188 fprintf(stderr,
"Env. variable, SM_FILL, is invalid.\n");
196 if(sSafeMemList==
NULL)
211 if((start=(
char *)malloc(nbytes+(2*sCheckSize)))==
NULL)
220 p->
start = start+sCheckSize;
225 for(i=0; i<sCheckSize; i++)
228 start[i+nbytes+sCheckSize]=sBlank;
231 return((
void *)(p->
start));
253 for(p=sSafeMemList; p!=
NULL;
NEXT(p))
257 if(p->
start==(
char *)ptr)
260 for(i=sCheckSize; i>0; i--)
262 if((*(p->
start-i) != sBlank))
264 fprintf(stderr,
"safefree(): Array underflow at \
265 %lu by %d bytes\n", (
ULONG)ptr,i);
271 for(i=sCheckSize-1; i>=0; i--)
275 fprintf(stderr,
"safefree(): Array overflow at \
276 %lu by %d bytes\n", (
ULONG)ptr,i+1);
283 free(p->
start-sCheckSize);
286 if(p == sSafeMemList)
305 fprintf(stderr,
"safefree(): Bad address passed to free: %lu\n",
307 fprintf(stderr,
" %d items in memory list\n",count);
325 for(p=sSafeMemList; p!=
NULL;
NEXT(p))
329 fprintf(stderr,
"safeleaks(): Leaked memory at: %lu of size: \
331 (
long unsigned)p->
start, (
long unsigned)p->
length);
#define ALLOCNEXTPREV(x, y)
void * blSafemalloc(int nbytes)
System-type variable type definitions.
BOOL blSafefree(void *ptr)