Open luckychengww opened 1 week ago
I can see this needs clarifying in the documentation for the function, it's not at all clear.
mosquitto_broker_publish_copy()
takes a copy of the payload, whereas mosquitto_broker_publish()
takes ownership of the payload, meaning that it will later free it and it must be allocated on the heap. In your case, "test-message"
is not allocated on the heap, so when the broker later tries to free it, there is a crash
I can see this needs clarifying in the documentation for the function, it's not at all clear.
mosquitto_broker_publish_copy()
takes a copy of the payload, whereasmosquitto_broker_publish()
takes ownership of the payload, meaning that it will later free it and it must be allocated on the heap. In your case,"test-message"
is not allocated on the heap, so when the broker later tries to free it, there is a crash
thank you very much
I'm going to develop a plugin using "mosquitto_broker_publish" function, but it casue mosquitto broker "Segmentation fault" after client connect. But when i use "mosquitto_broker_publish_copy" function instead,it's went ok. what's the reasion?
Below is my plugin code