adapter: Fix leaking filter pattern
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 11 Jun 2020 20:16:29 +0000 (13:16 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:49 +0000 (14:30 +0530)
When a discovery client has set a pattern as filter the code allocates
the string so it needs to be freed with the filter otherwise it leads to
the following leak:

10 bytes in 2 blocks are definitely lost in loss record 19 of 265
   at 0x483980B: malloc (vg_replace_malloc.c:309)
   by 0x4D9FF7E: strdup (in /usr/lib64/libc-2.30.so)
   by 0x1FC8E7: parse_pattern (adapter.c:2454)
   by 0x1FF37B: parse_discovery_filter_entry (adapter.c:2480)
   by 0x1FF37B: parse_discovery_filter_dict (adapter.c:2538)
   by 0x2020AF: set_discovery_filter (adapter.c:2589)
   by 0x24AD63: process_message.isra.0 (object.c:259)
   by 0x24B40F: generic_message (object.c:1079)
   by 0x4A670B7: ??? (in /usr/lib64/libdbus-1.so.3.19.11)
   by 0x4A57763: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.19.11)
   by 0x2459CF: message_dispatch (mainloop.c:72)
   by 0x4963E8A: ??? (in /usr/lib64/libglib-2.0.so.0.6200.6)
   by 0x496756F: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6200.6)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c

index 8ac3c51..cc97d61 100644 (file)
@@ -2014,6 +2014,7 @@ static void free_discovery_filter(struct discovery_filter *discovery_filter)
                return;
 
        g_slist_free_full(discovery_filter->uuids, free);
+       free(discovery_filter->pattern);
        g_free(discovery_filter);
 }