Fix dialog memory leakage

If a dialog was canceled it was never closed