Hi Folks,
I have encountered what looks like a memory leak in messenger if someone could
verify?
I have attached some code which runs under valgrind --leak-check=full to
produce the following output.
Can anyone verify if there is a way to clean this up or is this a leak in
proton-c 0.5?
Cheers,
Frank
==21663== Memcheck, a memory error detector
==21663== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==21663== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==21663== Command: ./qpid_messenger_leak_repro
==21663==
Waiting on recv
==21663==
==21663== HEAP SUMMARY:
==21663== in use at exit: 376,057 bytes in 3,417 blocks
==21663== total heap usage: 4,110 allocs, 693 frees, 763,143 bytes allocated
==21663==
==21663== 142,153 (2,776 direct, 139,377 indirect) bytes in 1 blocks are
definitely lost in loss record 996 of 997
==21663== at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==21663== by 0x4C232CF: pn_new (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C336AD: pn_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C421EC: pn_messenger_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C424DC: pn_messenger_tsync (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C42695: pn_messenger_sync (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C44301: pn_messenger_recv (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x400C43: qpidListenerThread (qpid_messenger_leak_repro.c:18)
==21663== by 0x3702407D14: start_thread (pthread_create.c:308)
==21663== by 0x37020F253C: clone (clone.S:114)
==21663==
==21663== 142,168 (2,776 direct, 139,392 indirect) bytes in 1 blocks are
definitely lost in loss record 997 of 997
==21663== at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==21663== by 0x4C232CF: pn_new (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C336AD: pn_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C421EC: pn_messenger_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C42F48: pn_messenger_resolve (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C4310B: pn_messenger_link (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C4333C: pn_messenger_target (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C43DDE: pn_messenger_put (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x400D40: main (qpid_messenger_leak_repro.c:79)
==21663==
==21663== LEAK SUMMARY:
==21663== definitely lost: 5,552 bytes in 2 blocks
==21663== indirectly lost: 278,769 bytes in 388 blocks
==21663== possibly lost: 0 bytes in 0 blocks
==21663== still reachable: 91,736 bytes in 3,027 blocks
==21663== suppressed: 0 bytes in 0 blocks
==21663== Reachable blocks (those to which a pointer was found) are not shown.
==21663== To see them, rerun with: --leak-check=full --show-reachable=yes
==21663==
==21663== For counts of detected and suppressed errors, rerun with: -v
==21663== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)
------------------------------------------------------------------------------
Please consider the environment before printing this email.
Visit our website at http://www.nyse.com <http://www.nyse.com>
*****************************************************************************
Note: The information contained in this message and any attachment to it is
privileged, confidential and protected from disclosure. If the reader of this
message is not the intended recipient, or an employee or agent responsible for
delivering this message to the intended recipient, you are hereby notified that
any dissemination, distribution or copying of this communication is strictly
prohibited. If you have received this communication in error, please notify the
sender immediately by replying to the message, and please delete it from your
system. Thank you. NYSE Euronext.
#include <proton/messenger.h>
#include <proton/error.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#define PUB_ADDRESS "amqp://127.0.0.1:6666/SOURCENAME"
#define SUB_ADDRESS "amqp://~127.0.0.1:6666/SOURCENAME"
void* qpidListenerThread (void* closure)
{
pn_messenger_t* mSub = (pn_messenger_t*)closure;
pn_message_t* tmpMsg = pn_message();
/* Block until explicit exit */
printf ("Waiting on recv\n");
/* Blocks until message received */
if (pn_messenger_recv (mSub, 1))
{
/* Will get in here if recv failed */
printf ("Error receiving message\n");
return NULL ;
}
/* Parse data received */
while (pn_messenger_incoming (mSub))
{
if (pn_messenger_get (mSub, tmpMsg))
{
printf("Error getting message\n");
}
/* Free this message before returning */
pn_message_free (tmpMsg);
return NULL;
}
return NULL ;
}
/*
* When running this application with valgrind --leak-check=full
*
* $ valgrind --leak-check=full ./qpid_messenger_leak_repro
*
==21663== Memcheck, a memory error detector
==21663== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==21663== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==21663== Command: ./qpid_messenger_leak_repro
==21663==
Waiting on recv
==21663==
==21663== HEAP SUMMARY:
==21663== in use at exit: 376,057 bytes in 3,417 blocks
==21663== total heap usage: 4,110 allocs, 693 frees, 763,143 bytes allocated
==21663==
==21663== 142,153 (2,776 direct, 139,377 indirect) bytes in 1 blocks are
definitely lost in loss record 996 of 997
==21663== at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==21663== by 0x4C232CF: pn_new (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C336AD: pn_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C421EC: pn_messenger_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C424DC: pn_messenger_tsync (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C42695: pn_messenger_sync (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C44301: pn_messenger_recv (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x400C43: qpidListenerThread (qpid_messenger_leak_repro.c:18)
==21663== by 0x3702407D14: start_thread (pthread_create.c:308)
==21663== by 0x37020F253C: clone (clone.S:114)
==21663==
==21663== 142,168 (2,776 direct, 139,392 indirect) bytes in 1 blocks are
definitely lost in loss record 997 of 997
==21663== at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==21663== by 0x4C232CF: pn_new (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C336AD: pn_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C421EC: pn_messenger_connection (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C42F48: pn_messenger_resolve (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C4310B: pn_messenger_link (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C4333C: pn_messenger_target (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x4C43DDE: pn_messenger_put (in
/home/fquinn/lib/qpid-proton-0.5/lib64/libqpid-proton.so.2.0.0)
==21663== by 0x400D40: main (qpid_messenger_leak_repro.c:79)
==21663==
==21663== LEAK SUMMARY:
==21663== definitely lost: 5,552 bytes in 2 blocks
==21663== indirectly lost: 278,769 bytes in 388 blocks
==21663== possibly lost: 0 bytes in 0 blocks
==21663== still reachable: 91,736 bytes in 3,027 blocks
==21663== suppressed: 0 bytes in 0 blocks
==21663== Reachable blocks (those to which a pointer was found) are not shown.
==21663== To see them, rerun with: --leak-check=full --show-reachable=yes
==21663==
==21663== For counts of detected and suppressed errors, rerun with: -v
==21663== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 2 from 2)
*
*/
int main ()
{
pthread_t subscribe_thread;
int rc;
/* Create the publishing messenger */
pn_messenger_t* mPub = pn_messenger ("mPub");
pn_messenger_t* mSub = pn_messenger ("mSub");
/* Activate the messengers */
pn_messenger_start (mPub);
pn_messenger_start (mSub);
pn_messenger_subscribe(mSub, SUB_ADDRESS);
pthread_create (&subscribe_thread,
NULL,
qpidListenerThread,
(void*)mSub);
/* Create the payload to be sent */
pn_message_t* outMsg = pn_message ();
/* Create the messenger for publishing out this desist message */
pn_message_set_address (outMsg, PUB_ADDRESS);
pn_messenger_put (mPub, outMsg);
pn_messenger_send (mPub, -1);
/* Rejoin the thread */
pthread_join (subscribe_thread, NULL);
/* Free outgoing message */
pn_message_free (outMsg);
/* Free the messengers */
pn_messenger_interrupt (mSub);
pn_messenger_stop (mSub);
pn_messenger_free (mSub);
pn_messenger_interrupt (mPub);
pn_messenger_stop (mPub);
pn_messenger_free (mPub);
}