fix potential memory error in latex