diff options
author | Jon Burgess <jburgess777@gmail.com> | 2018-10-14 19:11:21 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2018-10-21 16:39:33 +0200 |
commit | 08cbe9221676f380c3890c99d2d17bfe24bee346 (patch) | |
tree | c057052b2f6e8f6a2d12bee2d56ef2e1204f428e /tests | |
parent | 9a9f5a7a52d47a6e41048d943a2ab7e54e0948ce (diff) | |
download | libsigrokdecode-08cbe9221676f380c3890c99d2d17bfe24bee346.tar.gz libsigrokdecode-08cbe9221676f380c3890c99d2d17bfe24bee346.zip |
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)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/session.c | 10 |
1 files changed, 8 insertions, 2 deletions
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); } /* |