Implementation of malloc, free, and realloc