diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 4bf25e32e0..87d743b617 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -730,7 +730,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, /* Two dots? Then chop off the last bit of what we already found out. */ if (path_equal(first, "/..")) { _cleanup_free_ char *parent = NULL; - int fd_parent = -1; + _cleanup_close_ int fd_parent = -1; /* If we already are at the top, then going up will not change anything. This is in-line with * how the kernel handles this. */ @@ -765,6 +765,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, safe_close(fd); fd = fd_parent; + fd_parent = -1; continue; }