ctrl_blk* ctrl_blk::make_blk( void* p , const std::size_t sz ){ struct null_deleter { void operator()( void* ) { } }; return make_blk( p , sz , null_deleter()); }
/* * fda_malloc - allocate size chunk of memory and create debug * records for it. */ void* fda_malloc(size_t size, const char* file, int line) { void* p; size_t blk_size; Location* location; assert(0 < size); assert(0 != file); assert(sizeof(void*) == sizeof(size_t)); /* * memory limiter do not allocate more than byteLimit */ if ((size + byteCount) > byteLimit) return 0; /* * Make sure that there is enough room for prefix/postfix * and we get an aligned buffer */ blk_size = BASE_SIZE(size); if ((p = malloc(blk_size)) == 0) { lowMemFn(); if ((p = malloc(blk_size)) == 0) noMemFn(); } /* * don't allow malloc to fail */ assert(0 != p); /* * shred the memory and set bounds markers */ SHRED_MEM(p, blk_size); *((size_t*) p) = DEADBEEF; *((size_t*) (BYTE_PTR(p) + blk_size - S_SIZE)) = DEADBEEF; /* * find the location or create a new one */ if (0 == (location = findLocation(file, line))) { if (0 == (location = addLocation(file, line))) { free(p); noMemFn(); } } /* * don't allow noMemFn to return */ assert(0 != location); if (!make_blk(BYTE_PTR(p) + S_SIZE, size, location)) { if (0 == location->count) freeLocation(location); free(p); p = 0; noMemFn(); } /* * don't allow noMemFn to return */ assert(0 != p); return (BYTE_PTR(p) + S_SIZE); }