changeset 221:a4b93a2ed879

* close a file descriptor after we've shutdown() both sides, to avoid a leak
author Matt Johnston <matt@ucc.asn.au>
date Fri, 08 Jul 2005 15:04:06 +0000
parents 9089929fb2b7
children f3ef0d29ab65
files common-channel.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common-channel.c	Fri Jul 08 14:28:21 2005 +0000
+++ b/common-channel.c	Fri Jul 08 15:04:06 2005 +0000
@@ -1019,6 +1019,7 @@
 
 	/* XXX server */
 	if (channel->type->sepfds) {
+		TRACE(("shutdown((%d), %d)", fd, how))
 		shutdown(fd, how);
 		if (how == 0) {
 			closeout = 1;
@@ -1043,4 +1044,11 @@
 	if (closein && (channel->extrabuf != NULL) && (fd == channel->errfd)) {
 		channel->errfd = FD_CLOSED;
 	}
+
+	/* if we called shutdown on it and all references are gone, then we 
+	 * need to close() it to stop it lingering */
+	if (channel->type->sepfds && channel->outfd == FD_CLOSED 
+		&& channel->infd == FD_CLOSED && channel->errfd == FD_CLOSED) {
+		close(fd);
+	}
 }