aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>2021-09-02 19:06:30 +0300
committerAndriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>2021-09-02 19:06:30 +0300
commit537e8fb05c31fab3ab447f0a4e222b1091245a1a (patch)
tree373ddedfde306a1efa1c246621c6c093282a3c84
parent87f8fa282d76da55fe61651a5ee49a29632e9d7c (diff)
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 <andriy.tryshnivskyy@opensynergy.com> Change-Id: I72658ffd9f3b43a4ff71346f7fe4cf2c8f1242ca
-rw-r--r--binding/iiodevices-binding.c10
1 files 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;
}