Fix path closing in some cases.