Hi, I think I have found a memory leak in nanomsg and a way to fix it. We have noticed this memory leak in our app, but couldn't reproduce it in a unit test. However, I finally managed to track it down and I think it is due to the fact that in nn_xsub_recv() the message is re-used without being freed. I'm not sure I have fully understood the message allocation scheme in nanomsg, but from what I have understood, as soon as a XX_recv() function does not return an error, a message has been allocated and the user should free it. The attached patch fixes the memory leak (of course, there may be a better/cleaner fix but I'm not familiar enough with nanomsg code to be sure). This patch is under MIT licence. Best regards, Rémy -- Rémy BRUNO Trinnov Audio remy.bruno@xxxxxxxxxxx / http://www.trinnov.com 5 rue Edmond Michelet, 93360 Neuilly-Plaisance, France Tel: +33 (0)1 47 06 61 37 Mob: +33 (0)6 83 04 01 31
diff -r ebf26436a269 nanomsg/src/protocols/pubsub/xsub.c --- a/nanomsg/src/protocols/pubsub/xsub.c Tue Aug 26 18:12:40 2014 +0200 +++ b/nanomsg/src/protocols/pubsub/xsub.c Fri Oct 24 14:37:33 2014 +0200 @@ -176,7 +176,10 @@ rc = nn_trie_match (&xsub->trie, nn_chunkref_data (&msg->body), nn_chunkref_size (&msg->body)); if (rc == 0) + { + nn_msg_term(msg); continue; + } if (rc == 1) return 0; errnum_assert (0, -rc);