summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-01-21 19:07:10 +0900
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:50:12 +0200
commit5316104a4b756b0fa2261f60d41df47dd6e7feeb (patch)
tree7d8d5426e674c4a76a65afa2c65cc636a075f918 /src/basic/fs-util.c
parent423978fc39d86474b46c1be4d4511941fb584dff (diff)
fs-util: use _cleanup_close_ attribute
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.
Diffstat (limited to 'src/basic/fs-util.c')
-rw-r--r--src/basic/fs-util.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index 07aeff0af..eec1fbb37 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -745,7 +745,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. */
@@ -780,6 +780,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
safe_close(fd);
fd = fd_parent;
+ fd_parent = -1;
continue;
}