@@ -240,7 +240,6 @@ void context__send_will(struct mosquitto *ctxt)
240240 & ctxt -> will -> properties );
241241 }
242242 }
243-
244243 will__clear (ctxt );
245244}
246245
@@ -259,6 +258,15 @@ void context__disconnect(struct mosquitto *context, int reason)
259258 }
260259 }
261260#endif
261+ if (context -> id ){
262+ struct mosquitto * context_found ;
263+ HASH_FIND (hh_id , db .contexts_by_id_delayed_auth , context -> id , strlen (context -> id ), context_found );
264+ if (context_found == context ){
265+ net__socket_close (context );
266+ context__add_to_disused (context );
267+ return ;
268+ }
269+ }
262270
263271 if (context -> session_expiry_interval == 0 ){
264272 plugin__handle_disconnect (context , reason );
@@ -353,17 +361,22 @@ void context__remove_from_by_id(struct mosquitto *context)
353361{
354362 struct mosquitto * context_found ;
355363
356- if (context -> in_by_id == true && context -> id ){
357- HASH_FIND (hh_id , db .contexts_by_id_delayed_auth , context -> id , strlen (context -> id ), context_found );
358- if (context_found ){
359- HASH_DELETE (hh_id , db .contexts_by_id_delayed_auth , context_found );
360- }
364+ if (!context -> id ){
365+ return ;
366+ }
361367
368+ if (context -> in_by_id ){
362369 HASH_FIND (hh_id , db .contexts_by_id , context -> id , strlen (context -> id ), context_found );
363- if (context_found ){
370+ if (context_found == context ){
364371 HASH_DELETE (hh_id , db .contexts_by_id , context_found );
365372 }
366373 context -> id_hashv = 0 ;
367374 context -> in_by_id = false;
375+ return ;
376+ }
377+
378+ HASH_FIND (hh_id , db .contexts_by_id_delayed_auth , context -> id , strlen (context -> id ), context_found );
379+ if (context_found == context ){
380+ HASH_DELETE (hh_id , db .contexts_by_id_delayed_auth , context_found );
368381 }
369382}
0 commit comments