Просмотр исходного кода

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 лет назад
Родитель
Сommit
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;