Fixes possible undefined behaviour due to non-virtual destructor.