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)
commit9ad19b4c5779e060b426c0f20385bc53ba47d425
tree8c70b5312eb12b5d7da80a228936b58431548e1c
parent96db64091399848d8306f9d94555aaf7e78ea157
p2p: Fix not freed channel allocated in p2p_bind

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