malloc equivalent written in c