finish ex-1.c for heap and fit for valgrind