Skip to content

Invalid read of size 4 #1633

@entc

Description

@entc

Describe the bug
Valgrind is reporting a "Invalid read of size 4"

Without running valgrind this probably means, that the application using the paho.mqtt library might be crashing

Normally everything with the library is fine. Exception is, that sometimes we generate bigger messages and we see this error in the log. This can be stable reproduced.

Full Output:

Invalid read of size 4
==26077== at 0x8565D85: MQTTClient_publish5 (MQTTClient.c:2488)
==26077== by 0x85660A9: MQTTClient_publishMessage5 (MQTTClient.c:2552)
==26077== by 0x8566216: MQTTClient_publishMessage (MQTTClient.c:2572)
==26077== by 0x5501707: qbus_pvd_con_snd (qbus_mqtt.c:565)
==26077== by 0x4863621: qbus_engine_con_snd (qbus_engines.c:314)
==26077== by 0x4864969: qbus_con_snd (qbus_con.c:336)
==26077== by 0x486203A: qbus_on_res (qbus.c:93)
==26077== by 0x4866038: qbus_methods_response (qbus_methods.c:293)
==26077== by 0x4866216: qbus_methods__queue__on_event (qbus_methods.c:361)
==26077== by 0x48AD663: cape_queue_pull (cape_queue.c:481)
==26077== by 0x48AD80B: cape_queue_next (cape_queue.c:574)
==26077== by 0x48AD856: cape_queue__worker__thread (cape_queue.c:587)
==26077== Address 0xb2f4ed0 is 16 bytes inside a block of size 96 free'd
==26077== at 0x484512B: free (vg_replace_malloc.c:884)
==26077== by 0x858061A: myfree (Heap.c:285)
==26077== by 0x857A502: ListUnlink (LinkedList.c:224)
==26077== by 0x857A5D4: ListRemove (LinkedList.c:259)
==26077== by 0x8568F8F: MQTTProtocol_handlePubacks (MQTTProtocolClient.c:481)
==26077== by 0x8566652: MQTTClient_cycle (MQTTClient.c:2656)
==26077== by 0x8561A8D: MQTTClient_run (MQTTClient.c:854)
==26077== by 0x4FAA571: start_thread (in /lib64/libc.so.6)
==26077== by 0x5029A63: clone (in /lib64/libc.so.6)
==26077== Block was alloc'd at
==26077== at 0x48427E5: malloc (vg_replace_malloc.c:393)
==26077== by 0x858022C: mymalloc (Heap.c:201)
==26077== by 0x856804C: MQTTProtocol_createMessage (MQTTProtocolClient.c:208)
==26077== by 0x8567EE7: MQTTProtocol_startPublish (MQTTProtocolClient.c:179)
==26077== by 0x8565CB7: MQTTClient_publish5 (MQTTClient.c:2460)
==26077== by 0x85660A9: MQTTClient_publishMessage5 (MQTTClient.c:2552)
==26077== by 0x8566216: MQTTClient_publishMessage (MQTTClient.c:2572)
==26077== by 0x5501707: qbus_pvd_con_snd (qbus_mqtt.c:565)
==26077== by 0x4863621: qbus_engine_con_snd (qbus_engines.c:314)
==26077== by 0x4864969: qbus_con_snd (qbus_con.c:336)
==26077== by 0x486203A: qbus_on_res (qbus.c:93)
==26077== by 0x4866038: qbus_methods_response (qbus_methods.c:293)

To Reproduce
Creatinging a big message

Trying to send the message with the following code:

// local objects
CapeString subscriber_topic = cape_str_fmt ("%c/%s", MQTT_TOPIC_PRE__BY_ID, cid);
CapeStream payload = cape_stream_new ();

MQTTClient_message mqtt_msg = MQTTClient_message_initializer;
MQTTClient_deliveryToken token;

// convert from frame into a byte stream
qbus_frame_serialize (frame, payload);

mqtt_msg.payload = (void*)cape_stream_data (payload);
mqtt_msg.payloadlen = (int)cape_stream_size (payload);
mqtt_msg.qos = 1;
mqtt_msg.retained = 0;

// send away
MQTTClient_publishMessage (self->client, subscriber_topic, &mqtt_msg, &token);

cape_stream_del (&payload);
cape_str_del(&subscriber_topic);

Expected behavior
No valgrind errors

** Environment (please complete the following information):**

  • OS Linux Gentoo
  • newest paho.mqtt.c from repo
  • application might run the code in parallel
  • no mutexes in place

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions