]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: use _cleanup_close_ attribute
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Jan 2018 10:07:10 +0000 (19:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 21 Jan 2018 10:07:14 +0000 (19:07 +0900)
The commit f14f1806e329fe92d01f15c22a384702f0cb4ae0 introduced CHASE_SAFE
flag. When the flag is set, then `fd_parent` may not be properly closed.
This sets `_cleanup_close_` attribute to `fd_parent`.
Thus, now `fd_parent` is always closed properly.

src/basic/fs-util.c

index 4bf25e32e017496e96170dd5b95da67109dc73c9..87d743b617b156e0b7623b2fbd81b30098c749f2 100644 (file)
@@ -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;
                 }