From 537e8fb05c31fab3ab447f0a4e222b1091245a1a Mon Sep 17 00:00:00 2001 From: Andriy Tryshnivskyy Date: Thu, 2 Sep 2021 19:06:30 +0300 Subject: binding iiodevices: Fix service crash when subscribing to two iio devices. It fixes a segmentation fault when subscribing to two or more devices [1]. For every device, a client structure is created and stored in the linked list. If the device is not present, the corresponding client is removed from this list (it is done in deinit_client_sub()). There is an internal pointer last_client, which stores a pointer to the last client. The root cause for this bug is that last_client was not updated after the client was removed from the linked list. The solution is to not save the last pointer since it can be easily found when it is needed. 1: ON-REPLY 2:iiodevices/subscribe: ERROR { "jtype":"afb-reply", "request":{ "status":"aborted", "info":"signal Segmentation fault(11) caught" } } Issue: SPEC-4066 Signed-off-by: Andriy Tryshnivskyy Change-Id: I72658ffd9f3b43a4ff71346f7fe4cf2c8f1242ca --- binding/iiodevices-binding.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c index d2d1ae4..f39ec6d 100644 --- a/binding/iiodevices-binding.c +++ b/binding/iiodevices-binding.c @@ -71,8 +71,6 @@ static struct event *events = 0; static struct iio_context *ctx = NULL; /*clients*/ static struct client_sub * clients = NULL; -/*save last registered client*/ -static struct client_sub * last_client = NULL; /* Static definition of supported iiodevices */ static struct iio_info iio_infos[] = { @@ -504,9 +502,10 @@ static struct client_sub *add_new_client(struct iio_info *infos, client->index = 0; } else { - if(!last_client) { - AFB_API_ERROR(afbBindingV3root, "last_client should not be null"); - return NULL; + //find last client + struct client_sub * last_client = clients; + while(last_client->next!=NULL) { + last_client = last_client->next; } last_client->next = client; client->index = last_client->index + 1; @@ -526,7 +525,6 @@ static struct client_sub *add_new_client(struct iio_info *infos, client->dev = NULL; client->event = event_add(event_name); - last_client = client; return client; } -- cgit 1.2.3-korg