replaced malloc and free references