1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 17:58:12 +00:00

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.
This commit is contained in:
sin-ack 2022-01-18 13:09:59 +00:00 committed by Andreas Kling
parent 2d4261df49
commit 4d2e3de94c

View file

@ -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;