From 37478a9c00555be9d34599e39d8815f1b7489128 Mon Sep 17 00:00:00 2001 From: Ss Wang Date: Tue, 30 Jan 2024 11:50:01 +0800 Subject: [PATCH 1/2] add return to faile_message, avoid segment fault should not use response_topic when calloc failed --- lib/mqtt5_msg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mqtt5_msg.c b/lib/mqtt5_msg.c index fc04f71..da5d531 100644 --- a/lib/mqtt5_msg.c +++ b/lib/mqtt5_msg.c @@ -761,7 +761,7 @@ mqtt_message_t *mqtt5_msg_publish(mqtt_connection_t *connection, const char *top char *response_topic = calloc(1, response_topic_size); if (!response_topic) { ESP_LOGE(TAG, "Failed to calloc %d memory", response_topic_size); - fail_message(connection); + return fail_message(connection); } snprintf(response_topic, response_topic_size, "%s/%s", property->response_topic, resp_info); if (append_property(connection, MQTT5_PROPERTY_RESPONSE_TOPIC, 2, response_topic, response_topic_size) == -1) { From c06f1540fe4074b18efb3ad2af425ad36310a7f7 Mon Sep 17 00:00:00 2001 From: Ss Wang Date: Tue, 30 Jan 2024 12:05:45 +0800 Subject: [PATCH 2/2] set last_retransmit to now when first connected when published before connected, the msg will be always retransmitted immediately even it is send right now --- mqtt_client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mqtt_client.c b/mqtt_client.c index d4c074a..87177d6 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -1659,6 +1659,11 @@ static void esp_mqtt_task(void *pv) break; } + if (last_retransmit == 0) { + // connected for first time, set last_retransmit to now, avoid retransmit + last_retransmit = platform_tick_get_ms(); + } + // delete long pending messages mqtt_delete_expired_messages(client);