]> sigrok.org Git - libsigrokdecode.git/commitdiff
valgrind: safely iterate lists
authorKarl Palsson <redacted>
Fri, 25 Nov 2016 13:55:56 +0000 (13:55 +0000)
committerUwe Hermann <redacted>
Mon, 26 Dec 2016 21:50:17 +0000 (22:50 +0100)
Old versions triggered valgrind errors as the API method to remove an
entry modifies the list that was being iterated.

Signed-off-by: Karl Palsson <redacted>
decoder.c
srd.c

index eba5a287f4176008aed1568d465a13018c6be866..1151f057f2b5c3e2d4fa5f05ed0fda10cb7e7df6 100644 (file)
--- a/decoder.c
+++ b/decoder.c
@@ -992,13 +992,7 @@ SRD_API int srd_decoder_load_all(void)
  */
 SRD_API int srd_decoder_unload_all(void)
 {
-       GSList *l;
-       struct srd_decoder *dec;
-
-       for (l = pd_list; l; l = l->next) {
-               dec = l->data;
-               srd_decoder_unload(dec);
-       }
+       g_slist_foreach(pd_list, (GFunc)srd_decoder_unload, NULL);
        g_slist_free(pd_list);
        pd_list = NULL;
 
diff --git a/srd.c b/srd.c
index 2947ca8dd14bcda6073b41c4ee7e0c0a2d86f297..344919a07b75227c28d53fac0c9de3d0413fbc35 100644 (file)
--- a/srd.c
+++ b/srd.c
@@ -219,12 +219,9 @@ SRD_API int srd_init(const char *path)
  */
 SRD_API int srd_exit(void)
 {
-       GSList *l;
-
        srd_dbg("Exiting libsigrokdecode.");
 
-       for (l = sessions; l; l = l->next)
-               srd_session_destroy((struct srd_session *)l->data);
+       g_slist_foreach(sessions, (GFunc)srd_session_destroy, NULL);
 
        srd_decoder_unload_all();
        g_slist_free_full(searchpaths, g_free);