Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于mqtt_subscribe的topic_filter指针问题 #104

Open
youcanplay opened this issue Jul 5, 2024 · 0 comments
Open

关于mqtt_subscribe的topic_filter指针问题 #104

youcanplay opened this issue Jul 5, 2024 · 0 comments

Comments

@youcanplay
Copy link

在阅读源码时,发现mqtt_subscribe()函数里的msg_handler->topic_filter指针指向的是形参的地址,而没有保存完整的字符串内容。
如果topic_filter传入的是一个局部变量指向的缓冲区,调用mqtt_subscribe是不是会有问题?

int mqtt_subscribe(mqtt_client_t* c, const char* topic_filter, mqtt_qos_t qos, message_handler_t handler)
{
//.......
    /* create a message and record it */
    msg_handler = mqtt_msg_handler_create(topic_filter, qos, handler);
    if (NULL == msg_handler) {
        rc = MQTT_MEM_NOT_ENOUGH_ERROR;
        goto exit;
    }
//.......

}


static message_handlers_t *mqtt_msg_handler_create(const char* topic_filter, mqtt_qos_t qos, message_handler_t handler)
{
    message_handlers_t *msg_handler = NULL;

    msg_handler = (message_handlers_t *) platform_memory_alloc(sizeof(message_handlers_t));
    if (NULL == msg_handler)
        return NULL;
    
    mqtt_list_init(&msg_handler->list);
    
    msg_handler->qos = qos;
    msg_handler->handler = handler;     /* register  callback handler */
    msg_handler->topic_filter = topic_filter;    //这里仅保存了传入的指针,而没有保存完整的字符串内容。

    return msg_handler;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant