HW4:task1: fixed memory leaks