Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 57

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.3 - fix fd leak at multi-mount fail

From: Ian Kent <raven@themaw.net>

Fix file handle being left open following a multi-mount non-fatal mount
fail.
---

 daemon/direct.c |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)


--- autofs-5.0.1.orig/daemon/direct.c
+++ autofs-5.0.1/daemon/direct.c
@@ -1298,12 +1298,20 @@ static void *do_mount_direct(void *arg)
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
 	if (status) {
 		struct mapent *me;
+		struct statfs fs;
+		unsigned int close_fd = 0;
+
+		if (statfs(mt.name, &fs) == -1 ||
+		   (fs.f_type == AUTOFS_SUPER_MAGIC &&
+		    !master_find_submount(ap, mt.name)))
+			close_fd = 1;
 		cache_writelock(mt.mc);
-		me = cache_lookup_distinct(mt.mc, mt.name);
-		if (me)
+		if (!close_fd && (me = cache_lookup_distinct(mt.mc, mt.name)))
 			me->ioctlfd = mt.ioctlfd;
 		send_ready(ap->logopt, mt.ioctlfd, mt.wait_queue_token);
 		cache_unlock(mt.mc);
+		if (close_fd)
+			close(mt.ioctlfd);
 		info(ap->logopt, "mounted %s", mt.name);
 	} else {
 		send_fail(ap->logopt, mt.ioctlfd, mt.wait_queue_token);