Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Why the topic's length is set to zero?

Hi guys,

I was using the topic's length as a return from "message arrived" callback:

int on_message_arrived(
    void *context,
    char *topic_name,
    int topic_length,
    MQTTClient_message *message)
{
    MQTTClient_freeMessage(&message);
    MQTTClient_free(topic_name);

    return topic_length;
}

But the topic length is being zeroed, both at MQTTClient_run()
[https://github.com/eclipse/paho.mqtt.c/blob/develop/src/MQTTClient.c#L558-L559]
and at MQTTAsync_receiveThread()
[https://github.com/eclipse/paho.mqtt.c/blob/develop/src/MQTTAsync.c#L1679-L1680].
The zeroing is done by the snippet:

if (strlen(qe->topicName) == topicLen)
    topicLen = 0;

The question is, why are you zeroing the topic length passed to
"message arrived" callback? Why topicName length and topicLen  cannot
be equal?

I got there because I've noticed some invalid memory accesses when I
call MQTTClient_disconnect() after freeing a message through
MQTTClient_freeMessage(). I'm calling MQTTClient_disconnect() from the
"message arrived" callback. But the message seems to being freed
twice. Then, I figured out that this "message handler" should return
non-zero, so the message is removed from some internal message queue
[https://github.com/eclipse/paho.mqtt.c/blob/develop/src/MQTTClient.c#L570-L571].

Best regards,
Guilherme Ferreira


Back to the top