diff --git a/ChangeLog.txt b/ChangeLog.txt index 45c1a1dd..bf7e0fb2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,8 @@ Broker: - Fix retained messages not sent by bridges on outgoing topics at the first connection. Closes #701. - Minor documentation fixes. Closes #520. +- Fix duplicate clients being added to by_id hash before the old client was + removed. Closes #645. Build: - Various fixes to ease building. diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index de82ec3d..c6b3d6e5 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -208,6 +208,8 @@ struct mosquitto { #endif bool clean_session; #ifdef WITH_BROKER + char *old_id; /* for when a duplicate client connects, but we still want to + know what the id was */ bool is_dropping; bool is_bridge; struct mosquitto__bridge *bridge; diff --git a/src/context.c b/src/context.c index 495693e9..1d3ae163 100644 --- a/src/context.c +++ b/src/context.c @@ -161,6 +161,10 @@ void context__cleanup(struct mosquitto_db *db, struct mosquitto *context, bool d mosquitto__free(context->id); context->id = NULL; } + if(context->old_id){ + mosquitto__free(context->old_id); + context->old_id = NULL; + } packet__cleanup(&(context->in_packet)); if(context->current_out_packet){ packet__cleanup(context->current_out_packet); diff --git a/src/loop.c b/src/loop.c index 8df41760..97147209 100644 --- a/src/loop.c +++ b/src/loop.c @@ -638,12 +638,17 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context) context->sock = INVALID_SOCKET; context->pollfd_index = -1; } + HASH_DELETE(hh_id, db->contexts_by_id, context); + context->old_id = context->id; + context->id = NULL; }else #endif { if(db->config->connection_messages == true){ if(context->id){ id = context->id; + }else if(context->old_id){ + id = context->old_id; }else{ id = ""; }