implementation of malloc free and realloc