See the code below .
First 4 byes contains the no of bytes need to free.
void *malloc_flags(size_t size, lmm_flags_t flags)
{
oskit_size_t *chunk;
chunk = in_alloc(size + sizeof(oskit_size_t), flags);
if (chunk)
*chunk++ = size;
return chunk;
}
----------------------------------------------------------------------
void free_flags(void *chunk)
{
oskit_size_t size;
/* Posix says free of NULL does nothing */
if (! chunk)
return;
(oskit_size_t*)chunk -= 1;
size = *((oskit_size_t*)chunk);
in_free(chunk, size + sizeof(oskit_size_t));
}
=====================================================================
void *malloc(size_t size)
{
return malloc_flags(size,0);
}
---------------------------------------------------------------------
void free(void *chunk)
{
return free_flags(chunk);
}