Fixed memory leaks in IO classes.

Use virtual destructor in base classes to avoid leaks. Would be a good habit to always use them.