Fixed memory leaks with virtual destructor