Fixed potential memory leaks. 

Memory which is allocated using 'new T [n]' must always be deallocated by delete [].