|
|
1.1 ! root 1: /* ! 2: * notmem.c ! 3: * Test if pointer is in malloc arena. ! 4: */ ! 5: ! 6: #include <stdio.h> ! 7: #include <sys/malloc.h> ! 8: ! 9: /* ! 10: * Return 1 if cp is not in the malloc arena, ! 11: * 0 if cp is in the malloc arena, or ! 12: * -1 if trouble is detected in the arena. ! 13: * Note that this returns 0 for freed blocks in the arena. ! 14: */ ! 15: notmem(cp) char *cp; ! 16: { ! 17: register unsigned len, counter; ! 18: register MBLOCK *mp, *ap; ! 19: ! 20: if (cp == NULL ! 21: || (mp = __a_scanp) == NULL ! 22: || ((ap = mblockp(cp))->blksize) == 0) ! 23: return 1; /* obviously bad */ ! 24: ! 25: for (counter = __a_count; counter--; ) { ! 26: if (mp == ap) ! 27: return 0; /* obviously good */ ! 28: len = mp->blksize; ! 29: mp = (len) ? bumpp(mp, realsize(len)) : mp->uval.next; ! 30: } ! 31: if (mp != __a_scanp) ! 32: return -1; /* trouble in arena */ ! 33: return 1; /* not found */ ! 34: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.