summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantyn <frost.elemental@gmail.com>2018-08-24 12:00:12 +0300
committerChristoph Lipka <clipka@users.noreply.github.com>2018-08-24 11:00:12 +0200
commite1560eba378d1916a0a4eba2a54c9085fed49703 (patch)
treebd8a98e99b78f9803042ac22dc3c75fe0e73ae5e
parent22aea3931dde966f4aaf68a0aea045fbc036c266 (diff)
downloadDLT-daemon-e1560eba378d1916a0a4eba2a54c9085fed49703.tar.gz
dlt-daemon: fixed linked-list element remove (#71)
-rw-r--r--src/daemon/dlt_daemon_event_handler.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/daemon/dlt_daemon_event_handler.c b/src/daemon/dlt_daemon_event_handler.c
index b0d16dd..135130d 100644
--- a/src/daemon/dlt_daemon_event_handler.c
+++ b/src/daemon/dlt_daemon_event_handler.c
@@ -266,23 +266,31 @@ STATIC int dlt_daemon_remove_connection(DltEventHandler *ev,
{
return DLT_RETURN_ERROR;
}
- DltConnection **curr = &ev->connections;
+
+ DltConnection *curr = ev->connections;
+ DltConnection *prev = curr;
/* Find the address where to_remove value is registered */
- while (*curr && (*curr != to_remove))
+ while (curr && (curr != to_remove))
{
- curr = &(*curr)->next;
+ prev = curr;
+ curr = curr->next;
}
- if (!*curr)
+ if (!curr)
{
/* Must not be possible as we check for existence before */
dlt_log(LOG_CRIT, "Connection not found for removal.\n");
return -1;
}
-
- /* Replace the content of the address by the next value */
- *curr = (*curr)->next;
+ else if (curr == ev->connections)
+ {
+ ev->connections = curr->next;
+ }
+ else
+ {
+ prev->next = curr->next;
+ }
/* Now we can destroy our pointer */
dlt_connection_destroy(to_remove);