Adjust rig_list_foreach to allow use for unregistering

This patch changes rig_list_foreach such  that the called function may
call rig_unregister without having to access freed memory. This avoids
a valgrind  MemCheck and makes  it possible  to clean up  teh rig_list
database.
Hamlib-3.1
Bill Somerville 2016-06-10 01:13:57 +01:00
rodzic bf2b5c80ba
commit 4e53f99e51
1 zmienionych plików z 13 dodań i 10 usunięć

Wyświetl plik

@ -298,10 +298,13 @@ int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps*, rig_ptr_t),
return -RIG_EINVAL;
for (i=0; i<RIGLSTHASHSZ; i++) {
for (p=rig_hash_table[i]; p; p=p->next)
struct rig_list * next = NULL;
for (p=rig_hash_table[i]; p; p=next) {
next = p->next; /* read before call in case it is unregistered */
if ((*cfunc)(p->caps,data) == 0)
return RIG_OK;
}
}
return RIG_OK;
}