]> sigrok.org Git - libsigrokdecode.git/commit
Fix bad memory accesses during srd_exit()
authorJon Burgess <redacted>
Sun, 14 Oct 2018 17:49:52 +0000 (18:49 +0100)
committerUwe Hermann <redacted>
Sun, 21 Oct 2018 14:39:33 +0000 (16:39 +0200)
commit611a73404f1a42aa92fb32f00ca5407e1cdb2c71
treefe4323992f2a26693bb90ae23e965795c372f3e9
parent3a063627c5658a65790ff52a9c0ed9a1f660a0fb
Fix bad memory accesses during srd_exit()

When the decoder and session unload functions are called they
remove themselves from the list. The code walking the list
must be careful to avoid accessing the next pointer which
might now be invalid. The g_slist_foreach() takes care of
this.

Reports from Valgrind before fix:

==175436== Invalid read of size 8
--
==175436==  Address 0xe3f2598 is 8 bytes inside a block of size 16 free'd
==175436==    at 0x4C2FDAC: free (vg_replace_malloc.c:530)
==175436==    by 0x563C541: g_free (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x5654783: g_slice_free1 (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x56552A2: g_slist_remove (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x4E3FEFF: srd_session_destroy (session.c:343)
==175436==    by 0x4E3F5C7: srd_exit (srd.c:311)
==175436==    by 0x40336F: test_inst_new (inst.c:40)
==175436==    by 0x53E51D5: srunner_run_tagged (in /usr/lib64/libcheck.so.0.0.0)
==175436==    by 0x401237: main (main.c:51)
==175436==  Block was alloc'd at
==175436==    at 0x4C2EBAB: malloc (vg_replace_malloc.c:299)
==175436==    by 0x563C435: g_malloc (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x5654056: g_slice_alloc (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x5655797: g_slist_append (in /usr/lib64/libglib-2.0.so.0.5600.3)
==175436==    by 0x4E3FC75: srd_session_new (session.c:71)
==175436==    by 0x403345: test_inst_new (inst.c:37)
==175436==    by 0x53E51D5: srunner_run_tagged (in /usr/lib64/libcheck.so.0.0.0)
==175436==    by 0x401237: main (main.c:51)
decoder.c
srd.c