Patchwork [7/7] libjunction: fedfs_save_mode() leaks an open file descriptor

login
register
mail settings
Submitter Chuck Lever
Date Nov. 3, 2011, 3:29 p.m.
Message ID <20111103152914.2445.75529.stgit@degas.1015granger.net>
Download mbox | patch
Permalink /patch/123461/
State Accepted
Headers show

Comments

Chuck Lever - Nov. 3, 2011, 3:29 p.m.
Make sure the file descriptor opened by fedfs_open_path() is closed
before fedfs_save_mode() returns.  This bug would cause a leaked
open file descriptor for every junction created by rpc.fedfsd.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/libjunction/junction.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Patch

diff --git a/src/libjunction/junction.c b/src/libjunction/junction.c
index 73aa779..fa5fa7b 100644
--- a/src/libjunction/junction.c
+++ b/src/libjunction/junction.c
@@ -657,8 +657,10 @@  fedfs_save_mode(const char *pathname)
 
 	(void)snprintf(buf, sizeof(buf), "%o", ALLPERMS & stb.st_mode);
 
-	return fedfs_set_xattr(fd, pathname, FEDFSD_XATTR_NAME_MODE,
-				buf, strlen(buf));
+	retval = fedfs_set_xattr(fd, pathname, FEDFSD_XATTR_NAME_MODE,
+					buf, strlen(buf));
+	(void)close(fd);
+	return retval;
 }
 
 /**