Showing with 9 additions and 5 deletions.
  1. +9 −5 src/tk/mem.c
14 changes: 9 additions & 5 deletions src/tk/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ void *mem_calloc_debug(size_t n, const char *fil, int lin)
void mem_free_debug(void *ptr, const char *fil, int lin)
{
struct mem_debug *dl;
int error;

if (ptr == NULL)
return;
Expand All @@ -472,10 +473,11 @@ void mem_free_debug(void *ptr, const char *fil, int lin)
goto err2;
}
#if SUN || SUN386 /* Bus error if we read a long from an odd address */
if (memcmp(&dl->data[dl->Mnbytes],&afterval,sizeof(AFTERVAL)) != 0)
error = (memcmp(&dl->data[dl->Mnbytes],&afterval,sizeof(AFTERVAL)) != 0);
#else
if (*(long *) &dl->data[dl->Mnbytes] != AFTERVAL)
error = (*(long *) &dl->data[dl->Mnbytes] != AFTERVAL);
#endif
if (error)
{
PRINT "Pointer x%lx overrun\n",(long)ptr);
goto err2;
Expand Down Expand Up @@ -545,7 +547,8 @@ static void mem_checkdl(struct mem_debug *dl)
{ void *p;
#if (__SC__ || __DMC__) && !_WIN32
unsigned u;

int error;

/* Take advantage of fact that SC's allocator stores the size of the
* alloc in the unsigned immediately preceding the allocation.
*/
Expand All @@ -559,10 +562,11 @@ static void mem_checkdl(struct mem_debug *dl)
goto err2;
}
#if SUN || SUN386 /* Bus error if we read a long from an odd address */
if (memcmp(&dl->data[dl->Mnbytes],&afterval,sizeof(AFTERVAL)) != 0)
error = memcmp(&dl->data[dl->Mnbytes],&afterval,sizeof(AFTERVAL)) != 0;
#else
if (*(long *) &dl->data[dl->Mnbytes] != AFTERVAL)
error = *(long *) &dl->data[dl->Mnbytes] != AFTERVAL;
#endif
if (error)
{
PRINT "Pointer x%lx overrun\n",(long)p);
goto err2;
Expand Down