sem2hw2task1: Fixed memory leaks