From e5cc63a89bb20020607c8103b1c3d6c1dede3cbd Mon Sep 17 00:00:00 2001 From: Roger Light Date: Thu, 8 May 2014 23:05:34 +0100 Subject: [PATCH] Fix subscriptions sometimes being deleted. Fix subscriptions being deleted when clients subscribed to a topic beginning with a $ but that is not $SYS. Thanks to David Woodward. --- ChangeLog.txt | 4 ++-- src/subs.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 36691e49..1d36f22b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,8 +5,8 @@ Broker: - Ensure that bridges verify certificates by default when using TLS. - Fix possible crash when using pattern ACLs that do not include a %u and clients that connect without a username. - - +- Fix subscriptions being deleted when clients subscribed to a topic beginning + with a $ but that is not $SYS. Client library: - Fix topic matching edge case. diff --git a/src/subs.c b/src/subs.c index a58cf680..6194059f 100644 --- a/src/subs.c +++ b/src/subs.c @@ -377,7 +377,6 @@ int mqtt3_sub_add(struct mosquitto_db *db, struct mosquitto *context, const char _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); return MOSQ_ERR_NOMEM; } - child->next = NULL; child->topic = _mosquitto_strdup(tokens->topic); if(!child->topic){ _mosquitto_log_printf(NULL, MOSQ_LOG_ERR, "Error: Out of memory."); @@ -386,6 +385,11 @@ int mqtt3_sub_add(struct mosquitto_db *db, struct mosquitto *context, const char child->subs = NULL; child->children = NULL; child->retained = NULL; + if(db->subs.children){ + child->next = db->subs.children; + }else{ + child->next = NULL; + } db->subs.children = child; rc = _sub_add(db, context, qos, child, tokens);