From e1560eba378d1916a0a4eba2a54c9085fed49703 Mon Sep 17 00:00:00 2001 From: Konstantyn Date: Fri, 24 Aug 2018 12:00:12 +0300 Subject: dlt-daemon: fixed linked-list element remove (#71) --- src/daemon/dlt_daemon_event_handler.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src') 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); -- cgit v1.2.1