Skip to content

Commit

Permalink
Adjust rig_list_foreach to allow use for unregistering
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bill Somerville committed Jun 10, 2016
1 parent bf2b5c8 commit 4e53f99
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/register.c
Expand Up @@ -291,19 +291,22 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model)
*/
int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps*, rig_ptr_t),rig_ptr_t data)
{
struct rig_list *p;
int i;

if (!cfunc)
return -RIG_EINVAL;
struct rig_list *p;
int i;

for (i=0; i<RIGLSTHASHSZ; i++) {
for (p=rig_hash_table[i]; p; p=p->next)
if ((*cfunc)(p->caps,data) == 0)
return RIG_OK;
}
if (!cfunc)
return -RIG_EINVAL;

for (i=0; i<RIGLSTHASHSZ; i++) {
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;
}

static int dummy_rig_probe(const hamlib_port_t *p, rig_model_t model, rig_ptr_t data)
Expand Down

0 comments on commit 4e53f99

Please sign in to comment.