Skip to content

Commit 12f787f

Browse files
committed
Fix mqtt_subscribe does not work
when topic filter string passed to mqtt_subscribe via a local variable, topic subscribe is success but does not receive anything afterwards. This patch remove dependency of type of variable passed to mqtt_subscribe Signed-off-by: Ajay Bhargav <[email protected]>
1 parent b9fe254 commit 12f787f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

mqttclient/mqttclient.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,16 @@ static message_handlers_t *mqtt_msg_handler_create(const char* topic_filter, mqt
425425
{
426426
message_handlers_t *msg_handler = NULL;
427427

428-
msg_handler = (message_handlers_t *) platform_memory_alloc(sizeof(message_handlers_t));
428+
msg_handler = (message_handlers_t *) platform_memory_alloc(sizeof(message_handlers_t) + strlen(topic_filter) + 1);
429429
if (NULL == msg_handler)
430430
return NULL;
431431

432432
mqtt_list_init(&msg_handler->list);
433433

434434
msg_handler->qos = qos;
435435
msg_handler->handler = handler; /* register callback handler */
436-
msg_handler->topic_filter = topic_filter;
436+
msg_handler->topic_filter = (char *)msg_handler + sizeof(message_handlers_t);
437+
strcpy(msg_handler->topic_filter, topic_filter);
437438

438439
return msg_handler;
439440
}

mqttclient/mqttclient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef void (*reconnect_handler_t)(void* client, void* reconnect_date);
6969
typedef struct message_handlers {
7070
mqtt_list_t list;
7171
mqtt_qos_t qos;
72-
const char* topic_filter;
72+
char *topic_filter;
7373
message_handler_t handler;
7474
} message_handlers_t;
7575

0 commit comments

Comments
 (0)