From 9233b2b04f448d7e28bc0c36116d2ed64a4ce7d4 Mon Sep 17 00:00:00 2001 From: Martin Pärtel Date: Sun, 13 Sep 2015 20:28:33 +0100 Subject: bindfs_rmdir: fix leak if lstat fails and only call it when flag is set. bindfs_rmdir should never get called on a symlink unless --resolve_symlinks is set (or a race condition changes the target into a symlink). This means we can avoid the lstat if the flag is not set. This may slightly enhance code readability too. --- src/bindfs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/bindfs.c b/src/bindfs.c index 48a8693..ef5e46e 100644 --- a/src/bindfs.c +++ b/src/bindfs.c @@ -611,15 +611,19 @@ static int bindfs_rmdir(const char *path) if (real_path == NULL) return -errno; - if (lstat(real_path, &st) == -1) - return -errno; - - if (S_ISLNK(st.st_mode)) { - res = unlink(real_path); - free(real_path); - if (res == -1) + if (settings.resolve_symlinks) { + if (lstat(real_path, &st) == -1) { + free(real_path); return -errno; - return 0; + } + + if (S_ISLNK(st.st_mode)) { + res = unlink(real_path); + free(real_path); + if (res == -1) + return -errno; + return 0; + } } res = rmdir(real_path); -- cgit v1.2.3