From c6d09297cdeb623200e78e63fe9c064bf25cee68 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Sat, 22 Feb 2014 21:51:30 +0100 Subject: [PATCH] android/bluetooth: Fix memory leak in store_link_key If loading key file from file failed free key file. This fix following: 490 (40 direct, 450 indirect) bytes in 1 blocks are definitely lost in loss record 122 of 126 at 0x4028B4C: malloc (vg_replace_malloc.c:291) by 0x40A25B2: g_malloc (in /lib/i386-linux-gnu/ libglib-2.0.so.0.3800.2) by 0x40B8DB1: g_slice_alloc (in /lib/i386-linux-gnu/ libglib-2.0.so.0.3800.2) by 0x40B92DC: g_slice_alloc0 (in /lib/i386-linux-gnu/ libglib-2.0.so.0.3800.2) by 0x40946BB: g_key_file_new (in /lib/i386-linux-gnu/ libglib-2.0.so.0.3800.2) by 0x8054A84: new_link_key_callback (bluetooth.c:563) by 0x804FB44: notify_handler (mgmt.c:278) by 0x804F357: queue_foreach (queue.c:186) by 0x804FE6C: can_read_data (mgmt.c:290) by 0x804ED12: read_callback (io-glib.c:168) by 0x40E0CF4: ??? (in /lib/i386-linux-gnu/libglib-2.0.so.0.3800.2) by 0x409CAED: g_main_context_dispatch (in /lib/i386-linux-gnu/ libglib-2.0.so.0.3800.2) --- android/bluetooth.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 31092e3c7..66177e58f 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -562,8 +562,10 @@ static void store_link_key(const bdaddr_t *dst, const uint8_t *key, key_file = g_key_file_new(); - if (!g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL)) + if (!g_key_file_load_from_file(key_file, DEVICES_FILE, 0, NULL)) { + g_key_file_free(key_file); return; + } ba2str(dst, addr); -- 2.47.3