p2p: Fix not freed channel allocated in p2p_bind
authorWiktor Lawski <wiktor.lawski@tieto.com>
Wed, 19 Sep 2012 13:20:43 +0000 (15:20 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 21 Sep 2012 07:20:45 +0000 (09:20 +0200)
Channel was not freed because of non-zero reference count. Function
g_io_add_watch increments reference count (to value of 2 in p2p_bind). Pointer
to channel is not saved by neard, so the only one reference count decrement is
done by g_source_remove in function free_server_data. It is safe to decrement
reference count right after adding a watch.

Issue was reported by valgrind:

378 (360 direct, 18 indirect) bytes in 3 blocks are definitely lost in loss record 118 of 143
    at 0x4C2B6CD: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4E7FA78: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x4EB66F4: g_io_channel_unix_new (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x412102: p2p_listen (p2p.c:260)
    by 0x4E6A4DF: g_hash_table_foreach (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3200.3)
    by 0x417C06: near_device_driver_register (device.c:468)
    by 0x419771: __near_plugin_init (plugin.c:180)
    by 0x407E2E: main (main.c:214)

plugins/p2p.c

index b4943e5..845165f 100644 (file)
@@ -264,6 +264,7 @@ static int p2p_bind(struct near_p2p_driver *driver, uint32_t adapter_idx,
                                G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
                                p2p_listener_event,
                                (gpointer) server_data);
+       g_io_channel_unref(channel);
 
        server_list = g_list_append(server_list, server_data);