Fix #4533 - unregister callbacks on exception, fixing a memory leak