Implement a clear function which will free up all the malloc'd memory.