Fix potential leak of ClassFactory object.