I use the master branch and perform test the
MQTTAsync_publisher.c using valgrind, here is the output:
./vg ./MQTTAsync_publish
==30127== Memcheck, a memory error detector
==30127== Copyright (C) 2002-2011, and GNU GPL'd, by
Julian Seward et al.
==30127== Using Valgrind-3.7.0 and LibVEX; rerun with
-h for copyright info
==30127== Command: ./MQTTAsync_publish
==30127==
Waiting for publication of Hello World!
on topic MQTT Examples for client with ClientID:
ExampleClientPub
Successful connection
==30127== Thread 3:
==30127== Invalid read of size 4
==30127== at 0x4E39C7A: MQTTAsync_cycle (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x4E39E85: MQTTAsync_receiveThread (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x50E8E99: start_thread
(pthread_create.c:308)
==30127== Address 0x56e2cc8 is 8 bytes inside a block
of size 24 free'd
==30127== at 0x4C2A82E: free (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30127== by 0x4E34DAC: myfree (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x4E3E072: MQTTProtocol_handlePubacks
(in /usr/local/lib/libmqttv3a.so)
==30127== by 0x4E39C29: MQTTAsync_cycle (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x4E39E85: MQTTAsync_receiveThread (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x50E8E99: start_thread
(pthread_create.c:308)
==30127==
Message with token value 1 delivery confirmed
Successful disconnection
==30127==
==30127== HEAP SUMMARY:
==30127== in use at exit: 544 bytes in 2 blocks
==30127== total heap usage: 250 allocs, 248 frees,
139,498 bytes allocated
==30127==
==30127== Thread 1:
==30127== 272 bytes in 1 blocks are possibly lost in
loss record 1 of 2
==30127== at 0x4C29DB4: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30127== by 0x4012074: _dl_allocate_tls
(dl-tls.c:297)
==30127== by 0x4E410D0: Thread_start (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x4E3856A: MQTTAsync_connect (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x400E3B: main
(MQTTAsync_publish.c:129)
==30127==
==30127== 272 bytes in 1 blocks are possibly lost in
loss record 2 of 2
==30127== at 0x4C29DB4: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30127== by 0x4012074: _dl_allocate_tls
(dl-tls.c:297)
==30127== by 0x4E410D0: Thread_start (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x4E385AF: MQTTAsync_connect (in
/usr/local/lib/libmqttv3a.so)
==30127== by 0x400E3B: main
(MQTTAsync_publish.c:129)
==30127==
==30127== LEAK SUMMARY:
==30127== definitely lost: 0 bytes in 0 blocks
==30127== indirectly lost: 0 bytes in 0 blocks
==30127== possibly lost: 544 bytes in 2 blocks
==30127== still reachable: 0 bytes in 0 blocks
==30127== suppressed: 0 bytes in 0 blocks
==30127==
==30127== For counts of detected and suppressed errors,
rerun with: -v
==30127== ERROR SUMMARY: 3 errors from 3 contexts
(suppressed: 2 from 2)
I'm really sorry because I can't help to fix this memory
issue because org.eclipse.paho.mqtt.c is quite complex.
Could someone look at this report from valgrind. Should I
ignore this?