ソースを参照

LibCore: Don't manually close the fd when connection fails in sockets

This is wrong because we have already set the fd in the
PosixSocketHelper, and the destructor of the respective Socket class
will close the fd for us. With the manual closing of the fd, we attempt
to close the same fd twice which results in a crash.

Thanks to stelar7 for noticing this bug.
sin-ack 3 年 前
コミット
4d2e3de94c
1 ファイル変更3 行追加15 行削除
  1. 3 15
      Userland/Libraries/LibCore/Stream.cpp

+ 3 - 15
Userland/Libraries/LibCore/Stream.cpp

@@ -459,11 +459,7 @@ ErrorOr<NonnullOwnPtr<TCPSocket>> TCPSocket::connect(SocketAddress const& addres
     auto fd = TRY(create_fd(SocketDomain::Inet, SocketType::Stream));
     socket->m_helper.set_fd(fd);
 
-    auto result = connect_inet(fd, address);
-    if (result.is_error()) {
-        ::close(fd);
-        return result.release_error();
-    }
+    TRY(connect_inet(fd, address));
 
     socket->setup_notifier();
     return socket;
@@ -509,11 +505,7 @@ ErrorOr<NonnullOwnPtr<UDPSocket>> UDPSocket::connect(SocketAddress const& addres
     auto fd = TRY(create_fd(SocketDomain::Inet, SocketType::Datagram));
     socket->m_helper.set_fd(fd);
 
-    auto result = connect_inet(fd, address);
-    if (result.is_error()) {
-        ::close(fd);
-        return result.release_error();
-    }
+    TRY(connect_inet(fd, address));
 
     socket->setup_notifier();
     return socket;
@@ -526,11 +518,7 @@ ErrorOr<NonnullOwnPtr<LocalSocket>> LocalSocket::connect(String const& path)
     auto fd = TRY(create_fd(SocketDomain::Local, SocketType::Stream));
     socket->m_helper.set_fd(fd);
 
-    auto result = connect_local(fd, path);
-    if (result.is_error()) {
-        ::close(fd);
-        return result.release_error();
-    }
+    TRY(connect_local(fd, path));
 
     socket->setup_notifier();
     return socket;