Skip to content

Draft: gsocketlistener: Fix IPv4 listen() error handling

Philip Withnall requested to merge pwithnall/glib:1250-socket-listener-leak into main

In add_any_inet_port() for the case where we successfully listen()ed on IPv6, but failed to listen on IPv4, we would erroneously unref the IPv6 socket which we just gave away ownership of by adding it to priv->sockets.

However, given that we have a successful IPv6 socket, we shouldn’t report it as an error if the IPv4 listen() fails. While this code tries quite hard to return both sockets, returning only one seems to be the best we can do in this situation.

This issue was observed in an Android 4.4 ARM emulator. It’s possible the emulator deferred the bind() on the host until the listen() on the client.

Based on a patch by Ole André Vadla Ravnås oleavr@gmail.com.

#1250

Closes #1250

Edited by Philip Withnall

Merge request reports