From d19cbb825cd4566843d23f3539f4f4549ace243c Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 1 Aug 2019 15:47:48 +0100 Subject: [PATCH] Fix properties not being sent on QoS>0 PUBLISH messages. --- ChangeLog.txt | 1 + lib/actions.c | 13 ++++++++++++- lib/messages_mosq.c | 5 +++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 27b2c3e0..101e3fd7 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -24,6 +24,7 @@ Client library: client connects to a v3.x broker and is sent a CONNACK with the "unacceptable protocol version" connack reason code. - Fix memory leak when setting v5 properties in mosquitto_connect_v5(). +- Fix properties not being sent on QoS>0 PUBLISH messages. Clients: - mosquitto_pub: fix error codes not being returned when mosquitto_pub exits. diff --git a/lib/actions.c b/lib/actions.c index b17c560f..99d03f29 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -40,6 +40,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in uint16_t local_mid; const mosquitto_property *p; const mosquitto_property *outgoing_properties = NULL; + mosquitto_property *properties_copy = NULL; mosquitto_property local_property; bool have_topic_alias; int rc; @@ -109,8 +110,15 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in if(qos == 0){ return send__publish(mosq, local_mid, topic, payloadlen, payload, qos, retain, false, outgoing_properties, NULL, 0); }else{ + if(outgoing_properties){ + rc = mosquitto_property_copy_all(&properties_copy, outgoing_properties); + if(rc) return rc; + } message = mosquitto__calloc(1, sizeof(struct mosquitto_message_all)); - if(!message) return MOSQ_ERR_NOMEM; + if(!message){ + mosquitto_property_free_all(&properties_copy); + return MOSQ_ERR_NOMEM; + } message->next = NULL; message->timestamp = mosquitto_time(); @@ -119,6 +127,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in message->msg.topic = mosquitto__strdup(topic); if(!message->msg.topic){ message__cleanup(&message); + mosquitto_property_free_all(&properties_copy); return MOSQ_ERR_NOMEM; } } @@ -127,6 +136,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in message->msg.payload = mosquitto__malloc(payloadlen*sizeof(uint8_t)); if(!message->msg.payload){ message__cleanup(&message); + mosquitto_property_free_all(&properties_copy); return MOSQ_ERR_NOMEM; } memcpy(message->msg.payload, payload, payloadlen*sizeof(uint8_t)); @@ -137,6 +147,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in message->msg.qos = qos; message->msg.retain = retain; message->dup = false; + message->properties = properties_copy; pthread_mutex_lock(&mosq->msgs_out.mutex); message->state = mosq_ms_invalid; diff --git a/lib/messages_mosq.c b/lib/messages_mosq.c index bf77f5e6..75e4f860 100644 --- a/lib/messages_mosq.c +++ b/lib/messages_mosq.c @@ -39,6 +39,7 @@ void message__cleanup(struct mosquitto_message_all **message) mosquitto__free(msg->msg.topic); mosquitto__free(msg->msg.payload); + mosquitto_property_free_all(&msg->properties); mosquitto__free(msg); } @@ -199,7 +200,7 @@ int message__release_to_inflight(struct mosquitto *mosq, enum mosquitto_msg_dire }else if(cur->msg.qos == 2){ cur->state = mosq_ms_wait_for_pubrec; } - rc = send__publish(mosq, cur->msg.mid, cur->msg.topic, cur->msg.payloadlen, cur->msg.payload, cur->msg.qos, cur->msg.retain, cur->dup, NULL, NULL, 0); + rc = send__publish(mosq, cur->msg.mid, cur->msg.topic, cur->msg.payloadlen, cur->msg.payload, cur->msg.qos, cur->msg.retain, cur->dup, cur->properties, NULL, 0); if(rc){ return rc; } @@ -286,7 +287,7 @@ void message__retry_check(struct mosquitto *mosq) case mosq_ms_publish_qos2: msg->timestamp = now; msg->dup = true; - send__publish(mosq, msg->msg.mid, msg->msg.topic, msg->msg.payloadlen, msg->msg.payload, msg->msg.qos, msg->msg.retain, msg->dup, NULL, NULL, 0); + send__publish(mosq, msg->msg.mid, msg->msg.topic, msg->msg.payloadlen, msg->msg.payload, msg->msg.qos, msg->msg.retain, msg->dup, msg->properties, NULL, 0); break; case mosq_ms_wait_for_pubrel: msg->timestamp = now;