]> sigrok.org Git - libsigrokdecode.git/commitdiff
Fix memory leak in decoder test code
authorJon Burgess <redacted>
Sun, 14 Oct 2018 18:10:16 +0000 (19:10 +0100)
committerUwe Hermann <redacted>
Sun, 21 Oct 2018 14:39:33 +0000 (16:39 +0200)
==187724== 917 bytes in 1 blocks are definitely lost in loss record 3,046 of 3,207
==187724==    at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==187724==    by 0x563C435: g_malloc (in /usr/lib64/libglib-2.0.so.0.5600.3)
==187724==    by 0x5655D82: g_strdup (in /usr/lib64/libglib-2.0.so.0.5600.3)
==187724==    by 0x4E43937: py_str_as_str (util.c:371)
==187724==    by 0x4E415E1: srd_decoder_doc_get (decoder.c:892)
==187724==    by 0x40281D: test_doc_get (decoder.c:395)
==187724==    by 0x53E51D5: srunner_run_tagged (in /usr/lib64/libcheck.so.0.0.0)
==187724==    by 0x401237: main (main.c:51)

tests/decoder.c

index 2298d9334698af70e0cd4406cb16f825c1ce06f7..36784102bff934be9415bf657893e6b450757ac3 100644 (file)
@@ -388,11 +388,14 @@ END_TEST
 START_TEST(test_doc_get)
 {
        struct srd_decoder *dec;
+       char *doc;
 
        srd_init(DECODERS_TESTDIR);
        srd_decoder_load("uart");
        dec = srd_decoder_get_by_id("uart");
-       fail_unless(srd_decoder_doc_get(dec) != NULL);
+       doc = srd_decoder_doc_get(dec);
+       fail_unless(doc != NULL);
+       g_free(doc);
        srd_exit();
 }
 END_TEST