diff mbox series

[BlueZ,resend,7/9] health/mcap: Fix memory leak in mcl struct

Message ID 20240702142436.833138-8-hadess@hadess.net
State New
Headers show
Series Fix a number of static analysis issues #4 | expand

Commit Message

Bastien Nocera July 2, 2024, 2:23 p.m. UTC
Error: RESOURCE_LEAK (CWE-772): [#def40] [important]
bluez-5.76/profiles/health/mcap.c:2052:3: alloc_arg: "set_default_cb" allocates memory that is stored into "mcl->cb".
bluez-5.76/profiles/health/mcap.c:2055:4: leaked_storage: Freeing "mcl" without freeing its pointer field "cb" leaks the storage that "cb" points to.
2053|			if (util_getrandom(&val, sizeof(val), 0) < 0) {
2054|				mcap_instance_unref(mcl->mi);
2055|->				g_free(mcl);
2056|				goto drop;
2057|			}
---
 profiles/health/mcap.c | 1 +
 1 file changed, 1 insertion(+)
diff mbox series

Patch

diff --git a/profiles/health/mcap.c b/profiles/health/mcap.c
index b544b9a0a9b4..7eceaa88a3a9 100644
--- a/profiles/health/mcap.c
+++ b/profiles/health/mcap.c
@@ -2052,6 +2052,7 @@  static void connect_mcl_event_cb(GIOChannel *chan, GError *gerr,
 		set_default_cb(mcl);
 		if (util_getrandom(&val, sizeof(val), 0) < 0) {
 			mcap_instance_unref(mcl->mi);
+			g_free(mcl->cb);
 			g_free(mcl);
 			goto drop;
 		}