Skip to content

Commit cca9d9b

Browse files
committed
vsdebug: Fix double-closing listener FDs
While working on D88186184, I noticed that we were closing the listener FDs for the vsdebug server in both `waitForConnection` and `listenForClientConnection`. It does not seem to be causing issues in local testing but it could be a problem if the FD gets reused in a different thread in the meantime. `waitForConnection` is only called at the end of `listenForClientConnection` so closing the FDs only at the end of `listenForClientConnection` should be fine.
1 parent c7a529e commit cca9d9b

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

hphp/runtime/ext/vsdebug/socket_transport.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "hphp/util/configs/debugger.h"
2222
#include "hphp/util/user-info.h"
2323

24+
#include <algorithm>
25+
2426
#include <pwd.h>
2527
#include <grp.h>
2628

@@ -159,9 +161,7 @@ void SocketTransport::listenForClientConnection() {
159161
freeaddrinfo(ai);
160162
}
161163

162-
for (auto it = socketFds.begin(); it != socketFds.end(); it++) {
163-
close(*it);
164-
}
164+
std::for_each(socketFds.begin(), socketFds.end(), close);
165165

166166
close(abortFd);
167167
m_abortPipeFd[0] = -1;
@@ -574,10 +574,6 @@ void SocketTransport::waitForConnection(
574574
if (fds != nullptr) {
575575
free(fds);
576576
}
577-
578-
for (const int fd : socketFds) {
579-
close(fd);
580-
}
581577
};
582578

583579
// fds[0] will contain the read end of our "abort" pipe. Another thread will

0 commit comments

Comments
 (0)