Fix for fd leak when using TCP/IP forwarding

Ari Hyttinen ari.hyttinen at ailocom.com
Thu Jun 23 23:25:31 WST 2005


I encountered a FD leak in closechanfd function when using dbclient with 
-L and -R options at the same time.  Every forwarded connection 
(-R-direction) would leave an unclosed fd.  I don't know if the leak 
happens in other circumstances, I'm using only client and with both -L 
and -R.

Below is a fix.  It's not well tested, but seems to stop the leak, at 
least.  I haven't looked at the code before today, so maybe somebody 
more familiar with dropbear could comment on it...?

diff -u -b -B -w -p -r1.1.1.1 common-channel.c
--- common-channel.c    21 Jun 2005 14:20:29 -0000      1.1.1.1
+++ common-channel.c    23 Jun 2005 15:06:19 -0000
@@ -1057,4 +1058,8 @@ static void closechanfd(struct Channel *
        if (closein && (channel->extrabuf != NULL) && (fd == 
channel->errfd)) {
                channel->errfd = FD_CLOSED;
        }
+       if (channel->outfd == FD_CLOSED && channel->errfd == FD_CLOSED 
&& channel->errfd == FD_CLOSED && fd >= 0) {
+               close(fd);
+       }
+
 }


-- 
Ari Hyttinen





More information about the Dropbear mailing list