OSDN Git Service

gobex: g_obex_new should create its own GIOChannel ref
authorJohan Hedberg <johan.hedberg@intel.com>
Mon, 4 Jul 2011 08:17:48 +0000 (11:17 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 4 Dec 2012 21:21:58 +0000 (22:21 +0100)
gobex/gobex.c
tools/obex-server-tool.c
unit/test-gobex.c

index e684628..463ac3d 100644 (file)
@@ -663,7 +663,7 @@ GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
 
        obex = g_new0(GObex, 1);
 
-       obex->io = io;
+       obex->io = g_io_channel_ref(io);
        obex->ref_count = 1;
 
        obex->io_rx_mtu = io_rx_mtu;
index 3d93b92..b446a87 100644 (file)
@@ -80,9 +80,12 @@ static gboolean unix_accept(GIOChannel *chan, GIOCondition cond, gpointer data)
                                                                cli_sk);
 
        io = g_io_channel_unix_new(cli_sk);
+
        g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
+       g_io_channel_set_close_on_unref(io, TRUE);
 
        obex = g_obex_new(io, G_OBEX_TRANSPORT_STREAM, -1, -1);
+       g_io_channel_unref(io);
        g_obex_set_disconnect_function(obex, disconn_func, NULL);
        clients = g_slist_append(clients, obex);;
 
index 6aae16f..84006c9 100644 (file)
@@ -65,13 +65,17 @@ static GObex *create_gobex(int fd, GObexTransportType transport_type,
                                                gboolean close_on_unref)
 {
        GIOChannel *io;
+       GObex *obex;
 
        io = g_io_channel_unix_new(fd);
        g_assert(io != NULL);
 
        g_io_channel_set_close_on_unref(io, close_on_unref);
 
-       return g_obex_new(io, transport_type, -1, -1);
+       obex = g_obex_new(io, transport_type, -1, -1);
+       g_io_channel_unref(io);
+
+       return obex;
 }
 
 static void create_endpoints(GObex **obex, GIOChannel **io, int sock_type)