Fix crash or deadlock after calling saveXML().