adb: fix register_socket_transport related double-closes.
Multiple codepaths were closing the fd they passed into
register_socket_transport on failure, which would close the fd itself.
Switch things over to unique_fd to make it clear that we don't actually
have to close on failure.
Test: mma
Change-Id: I2d9bdcb1142c24931d970f99ebdf9a8051daf05c
diff --git a/adb/transport.cpp b/adb/transport.cpp
index 638940c..793c283 100644
--- a/adb/transport.cpp
+++ b/adb/transport.cpp
@@ -1157,7 +1157,7 @@
}
#endif // ADB_HOST
-int register_socket_transport(int s, const char* serial, int port, int local,
+int register_socket_transport(unique_fd s, const char* serial, int port, int local,
atransport::ReconnectCallback reconnect) {
atransport* t = new atransport(std::move(reconnect), kCsOffline);
@@ -1167,8 +1167,8 @@
serial = buf;
}
- D("transport: %s init'ing for socket %d, on port %d", serial, s, port);
- if (init_socket_transport(t, s, port, local) < 0) {
+ D("transport: %s init'ing for socket %d, on port %d", serial, s.get(), port);
+ if (init_socket_transport(t, std::move(s), port, local) < 0) {
delete t;
return -1;
}