From: Jon Burgess Date: Sun, 14 Oct 2018 18:11:21 +0000 (+0100) Subject: Fix GVariant memory leaks in session test code X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=08cbe9221676f380c3890c99d2d17bfe24bee346;p=libsigrokdecode.git Fix GVariant memory leaks in session test code ==187759== 88 (40 direct, 48 indirect) bytes in 1 blocks are definitely lost in loss record 2,262 of 3,218 ==187759== at 0x4C2EBAB: malloc (vg_replace_malloc.c:299) ==187759== by 0x563C435: g_malloc (in /usr/lib64/libglib-2.0.so.0.5600.3) ==187759== by 0x5654056: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.5600.3) ==187759== by 0x5673630: g_variant_new_from_bytes (in /usr/lib64/libglib-2.0.so.0.5600.3) ==187759== by 0x566C5E6: ??? (in /usr/lib64/libglib-2.0.so.0.5600.3) ==187759== by 0x566C7D2: g_variant_new_uint64 (in /usr/lib64/libglib-2.0.so.0.5600.3) ==187759== by 0x403D41: conf_check_fail.constprop.6 (session.c:152) ==187759== by 0x403E06: test_session_metadata_set_bogus (session.c:215) ==187759== by 0x53E51D5: srunner_run_tagged (in /usr/lib64/libcheck.so.0.0.0) ==187759== by 0x401237: main (main.c:51) --- diff --git a/tests/session.c b/tests/session.c index e79496e..73b7669 100644 --- a/tests/session.c +++ b/tests/session.c @@ -148,10 +148,13 @@ static void conf_check_ok(struct srd_session *sess, int key, uint64_t x) static void conf_check_fail(struct srd_session *sess, int key, uint64_t x) { int ret; + GVariant *value = g_variant_new_uint64(x); - ret = srd_session_metadata_set(sess, key, g_variant_new_uint64(x)); + ret = srd_session_metadata_set(sess, key, value); fail_unless(ret != SRD_OK, "srd_session_metadata_set(%p, %d, %" PRIu64 ") worked.", sess, key, x); + if (ret != SRD_OK) + g_variant_unref(value); } static void conf_check_fail_null(struct srd_session *sess, int key) @@ -166,10 +169,13 @@ static void conf_check_fail_null(struct srd_session *sess, int key) static void conf_check_fail_str(struct srd_session *sess, int key, const char *s) { int ret; + GVariant *value = g_variant_new_string(s); - ret = srd_session_metadata_set(sess, key, g_variant_new_string(s)); + ret = srd_session_metadata_set(sess, key, value); fail_unless(ret != SRD_OK, "srd_session_metadata_set() for key %d " "failed: %d.", key, ret); + if (ret != SRD_OK) + g_variant_unref(value); } /*