perform malloc and free