summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-06-15 13:42:38 (GMT)
committerAlexander Larsson <alexl@redhat.com>2009-06-15 13:42:38 (GMT)
commita640695f1609805a0fe745d35c2055a984410bb5 (patch)
treeab2d7177d816fea042506f3975083e307de1e033
parent67de6cba508d7f2e0c310527667df2efcf4a543a (diff)
downloadglib-a640695f1609805a0fe745d35c2055a984410bb5.tar.gz
glib-a640695f1609805a0fe745d35c2055a984410bb5.tar.xz
Ref the passed in socket in g_socket_listener_add_socket (#585599)
-rw-r--r--gio/gsocketlistener.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/gio/gsocketlistener.c b/gio/gsocketlistener.c
index 522ed44..d0025f5 100644
--- a/gio/gsocketlistener.c
+++ b/gio/gsocketlistener.c
@@ -234,6 +234,7 @@ g_socket_listener_add_socket (GSocketListener *listener,
return FALSE;
}
+ g_object_ref (socket);
g_ptr_array_add (listener->priv->sockets, socket);
if (source_object)
@@ -301,15 +302,13 @@ g_socket_listener_add_address (GSocketListener *listener,
g_socket_set_listen_backlog (socket, listener->priv->listen_backlog);
if (!g_socket_bind (socket, address, TRUE, error) ||
- !g_socket_listen (socket, error) ||
- !g_socket_listener_add_socket (listener, socket,
- source_object,
- error))
+ !g_socket_listen (socket, error))
{
g_object_unref (socket);
return FALSE;
}
+ local_address = NULL;
if (effective_address)
{
local_address = g_socket_get_local_address (socket, error);
@@ -318,9 +317,23 @@ g_socket_listener_add_address (GSocketListener *listener,
g_object_unref (socket);
return FALSE;
}
- *effective_address = local_address;
}
+ if (!g_socket_listener_add_socket (listener, socket,
+ source_object,
+ error))
+ {
+ if (local_address)
+ g_object_unref (local_address);
+ g_object_unref (socket);
+ return FALSE;
+ }
+
+ if (effective_address)
+ *effective_address = local_address;
+
+ g_object_unref (socket); /* add_socket refs this */
+
if (G_SOCKET_LISTENER_GET_CLASS (listener)->changed)
G_SOCKET_LISTENER_GET_CLASS (listener)->changed (listener);