Mercurial > dropbear
comparison common-channel.c @ 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 | c44df7123b0a |
children | c5d3ef11155f |
comparison
equal
deleted
inserted
replaced
220:9089929fb2b7 | 221:a4b93a2ed879 |
---|---|
1017 | 1017 |
1018 int closein = 0, closeout = 0; | 1018 int closein = 0, closeout = 0; |
1019 | 1019 |
1020 /* XXX server */ | 1020 /* XXX server */ |
1021 if (channel->type->sepfds) { | 1021 if (channel->type->sepfds) { |
1022 TRACE(("shutdown((%d), %d)", fd, how)) | |
1022 shutdown(fd, how); | 1023 shutdown(fd, how); |
1023 if (how == 0) { | 1024 if (how == 0) { |
1024 closeout = 1; | 1025 closeout = 1; |
1025 } else { | 1026 } else { |
1026 closein = 1; | 1027 closein = 1; |
1041 channel->infd = FD_CLOSED; | 1042 channel->infd = FD_CLOSED; |
1042 } | 1043 } |
1043 if (closein && (channel->extrabuf != NULL) && (fd == channel->errfd)) { | 1044 if (closein && (channel->extrabuf != NULL) && (fd == channel->errfd)) { |
1044 channel->errfd = FD_CLOSED; | 1045 channel->errfd = FD_CLOSED; |
1045 } | 1046 } |
1046 } | 1047 |
1048 /* if we called shutdown on it and all references are gone, then we | |
1049 * need to close() it to stop it lingering */ | |
1050 if (channel->type->sepfds && channel->outfd == FD_CLOSED | |
1051 && channel->infd == FD_CLOSED && channel->errfd == FD_CLOSED) { | |
1052 close(fd); | |
1053 } | |
1054 } |