Fix for exception thrown in destructor.

Signed-off-by: azurepine <azurepine@gmail.com>