From 4e53f99e517696d172ffc84ada81a78aa32c578e Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Fri, 10 Jun 2016 01:13:57 +0100 Subject: [PATCH] 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. --- src/register.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/register.c b/src/register.c index 72103d1ec..4a28ab9a7 100644 --- a/src/register.c +++ b/src/register.c @@ -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; + struct rig_list *p; + int i; - if (!cfunc) - return -RIG_EINVAL; - - for (i=0; inext) - if ((*cfunc)(p->caps,data) == 0) - return RIG_OK; - } + if (!cfunc) + return -RIG_EINVAL; + for (i=0; inext; /* 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)