implementation of malloc and free