OSDN Git Service

android/bluetooth: Fix memory leaks in load_devices_info
authorSzymon Janc <szymon.janc@tieto.com>
Fri, 20 Dec 2013 14:39:53 +0000 (15:39 +0100)
committerSzymon Janc <szymon.janc@tieto.com>
Fri, 20 Dec 2013 14:46:51 +0000 (15:46 +0100)
Groups and key file were not free on function return. This fix
following valgrind reports:

34 (16 direct, 18 indirect) bytes in 1 blocks are definitely lost in
loss record 33 of 77
   at 0x4C2A2DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-
amd64-linux.so)
   by 0x4E81DD0: g_malloc (in /lib/x86_64-linux-gnu/libglib-2.0.so
.0.3800.1)
   by 0x4E74BF1: g_key_file_get_groups (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x40CDFA: read_info_complete (bluetooth.c:1672)
   by 0x40827C: request_complete (mgmt.c:221)
   by 0x4085E9: received_data (mgmt.c:319)
   by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
   by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x403B15: main (main.c:439)

1,633 (72 direct, 1,561 indirect) bytes in 1 blocks are definitely lost
in loss record 75 of 77
   at 0x4C2A2DB: malloc (in /usr/lib/valgrind/
vgpreload_memcheck-amd64-linux.so)
   by 0x4E81DD0: g_malloc (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E9796D: g_slice_alloc (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E97EAD: g_slice_alloc0 (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E746DA: g_key_file_new (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x40CDD4: read_info_complete (bluetooth.c:1667)
   by 0x40827C: request_complete (mgmt.c:221)
   by 0x4085E9: received_data (mgmt.c:319)
   by 0x4E7C3B5: g_main_context_dispatch (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x4E7C707: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3800.1)
   by 0x4E7CB09: g_main_loop_run (in /lib/x86_64-linux-gnu/
libglib-2.0.so.0.3800.1)
   by 0x403B15: main (main.c:439)

android/bluetooth.c

index 48f5186..e534fc1 100644 (file)
@@ -1684,7 +1684,9 @@ static void load_devices_info(bt_bluetooth_ready cb)
        }
 
        load_link_keys(keys, cb);
+       g_strfreev(devs);
        g_slist_free_full(keys, g_free);
+       g_key_file_free(key_file);
 }
 
 static void read_info_complete(uint8_t status, uint16_t length,