From 2c0db6a669c8520675510b1ab4c2fc6811ad8092 Mon Sep 17 00:00:00 2001 From: Tuan PM Date: Thu, 1 Mar 2018 22:30:25 +0700 Subject: [PATCH] correct length and malloc storate for lwt binary message --- mqtt_client.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mqtt_client.c b/mqtt_client.c index 281bef5..c4f4cb2 100644 --- a/mqtt_client.c +++ b/mqtt_client.c @@ -125,14 +125,13 @@ static esp_err_t esp_mqtt_set_config(esp_mqtt_client_handle_t client, const esp_ client->connect_info.will_topic = strdup(config->lwt_topic); } - if (config->lwt_msg[0]) { + if (config->lwt_msg_len) { + client->connect_info.will_message = malloc(config->lwt_msg_len); + mem_assert(client->connect_info.will_message); + memcpy(client->connect_info.will_message, config->lwt_msg, config->lwt_msg_len); + } else if (config->lwt_msg[0]) { client->connect_info.will_message = strdup(config->lwt_msg); - if (config->lwt_msg_len > 0) { - client->connect_info.will_length = config->lwt_msg_len; - } - else { - client->connect_info.will_length = strlen(config->lwt_msg); - } + client->connect_info.will_length = strlen(config->lwt_msg); } client->connect_info.will_qos = config->lwt_qos;