examples: Avoid accessing list before acquiring lock

Thanks coverity

CID 1526592

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
This commit is contained in:
Jakub Jelen
2023-11-23 15:03:14 +01:00
parent 46ab527bbe
commit 54ac7c95e8

View File

@@ -343,10 +343,11 @@ static void delete_item(ssh_channel channel)
static node_t *search_item(ssh_channel channel) static node_t *search_item(ssh_channel channel)
{ {
node_t *current = node; node_t *current = NULL;
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
current = node;
while (current != NULL) { while (current != NULL) {
if (current->channel == channel) { if (current->channel == channel) {
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);