From 9cd5284afad0b1cf603cc5437e4cf143104ed717 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=D0=B5x=D0=B0nder=20Lysik=D0=BEv?=
 <alexander.lysikov@demlabs.net>
Date: Thu, 21 Nov 2019 17:10:13 +0500
Subject: [PATCH] removed stream from s_stream_keepalive_list before stream
 delete

---
 stream/dap_stream.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/stream/dap_stream.c b/stream/dap_stream.c
index 27eb4de..af49b03 100644
--- a/stream/dap_stream.c
+++ b/stream/dap_stream.c
@@ -342,25 +342,11 @@ dap_stream_t * stream_new(dap_http_client_t * a_sh)
 void dap_stream_delete( dap_stream_t *a_stream )
 {
 //    log_it(L_DEBUG,"dap_stream_delete( )");
-
     if(a_stream == NULL) {
         log_it(L_ERROR,"stream delete NULL instance");
         return;
     }
-    size_t i;
-
-    for(i = 0; i < a_stream->channel_count; i++) {
-        dap_stream_ch_delete(a_stream->channel[i]);
-    }
-
-    if ( a_stream->session ) {
-        dap_stream_session_close(a_stream->session->id);
-    }
-
-    pthread_mutex_lock(&s_mutex_keepalive_list);
-    DL_DELETE(s_stream_keepalive_list, a_stream);
     stream_dap_delete(a_stream->conn, NULL);
-    pthread_mutex_unlock(&s_mutex_keepalive_list);
     free(a_stream);
 }
 
@@ -703,11 +689,18 @@ void stream_dap_delete(dap_client_remote_t* sh, void * arg){
     if(sid == NULL)
         return;
     (void) arg;
+
+    pthread_mutex_lock(&s_mutex_keepalive_list);
+    DL_DELETE(s_stream_keepalive_list, sid);
+    pthread_mutex_unlock(&s_mutex_keepalive_list);
+
     size_t i;
     for(i=0;i<sid->channel_count; i++)
         dap_stream_ch_delete(sid->channel[i]);
+    sid->channel_count = 0;
     if(sid->session)
         dap_stream_session_close(sid->session->id);
+    sid->session = NULL;
     //free(sid);
     log_it(L_NOTICE,"[core] Stream connection is finished");
 }
-- 
GitLab