-struct malloced {
- struct malloced *next, *back;
- size_t sz;
- unsigned long count;
- struct { double d; long ul; void *p; void (*fp)(void); } data;
-};
-
-static unsigned long malloccount, mallocfailat;
-static struct { struct malloced *head, *tail; } mallocedlist;
-
-#define MALLOCHSZ ((char*)&mallocedlist.head->data - (char*)mallocedlist.head)
-
-void *Hmalloc(size_t sz) {
- struct malloced *newnode;
- const char *mfavar;
- char *ep;
-
- assert(sz);
-
- newnode= malloc(MALLOCHSZ + sz); if (!newnode) Tnomem();
-
- LIST_LINK_TAIL(mallocedlist,newnode);
- newnode->sz= sz;
- newnode->count= ++malloccount;
- if (!mallocfailat) {
- mfavar= getenv("ADNS_REGRESS_MALLOCFAILAT");
- if (mfavar) {
- mallocfailat= strtoul(mfavar,&ep,10);
- if (!mallocfailat || *ep) Tfailed("ADNS_REGRESS_MALLOCFAILAT bad value");
- } else {
- mallocfailat= ~0UL;
- }
- }
- assert(newnode->count != mallocfailat);
- memset(&newnode->data,0xc7,sz);
- return &newnode->data;
-}
-
-void Hfree(void *ptr) {
- struct malloced *oldnode;
-
- if (!ptr) return;
-
- oldnode= (void*)((char*)ptr - MALLOCHSZ);
- LIST_UNLINK(mallocedlist,oldnode);
- memset(&oldnode->data,0x38,oldnode->sz);
- free(oldnode);