Fixed memoryleak when filename not legal