diff mbox series

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

Message ID 20240702084900.773620-8-hadess@hadess.net (mailing list archive)
State Superseded
Headers show
Series Fix a number of static analysis issues #4 | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 4: B1 Line exceeds max length (117>80): "bluez-5.76/profiles/health/mcap.c:2052:3: alloc_arg: "set_default_cb" allocates memory that is stored into "mcl->cb"." 5: B1 Line exceeds max length (149>80): "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." 6: B3 Line contains hard tab characters (\t): "2053| if (util_getrandom(&val, sizeof(val), 0) < 0) {" 7: B3 Line contains hard tab characters (\t): "2054| mcap_instance_unref(mcl->mi);" 8: B3 Line contains hard tab characters (\t): "2055|-> g_free(mcl);" 9: B3 Line contains hard tab characters (\t): "2056| goto drop;" 10: B3 Line contains hard tab characters (\t): "2057| }"
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Bastien Nocera July 2, 2024, 8:47 a.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;
 		}