Fix potential crash while saving changes for a document.