zmsg_pop gives you a frame you have to destroy. Instead of zframe_strdup (zmsg_pop())
use zmsg_popstr () -Pieter On Thu, Sep 19, 2013 at 3:08 PM, Yauheni Baltouski <[email protected]> wrote: > Hi Mathias, > > According to CZMQ manual, construction like > char *msgData = zframe_strdup(zmsg_pop(m)); > zframe_t *frame = zmsg_pop(m); > > will return frame from message m and caller own this frame. > So you need to zframe_destroy(&frame) after you call zframe_strdup() > as it creates copy of > string in frame and you release only this copy mem, not zframe. > > 2013/9/19 Mathias Hablützel <[email protected]>: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Hi everyone, >> >> ran into a situation where my code seems to leak memory but I can't >> tackle it down in _my_ code. Kicked off valgrind to find this: >> >> ==2874== 56 bytes in 1 blocks are definitely lost in loss record 34 of 72 >> ==2874== at 0x4A08121: calloc (in >> /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) >> ==2874== by 0x4E7A968: zframe_new (czmq_prelude.h:443) >> ==2874== by 0x4E7AB48: zframe_recv (zframe.c:156) >> ==2874== by 0x4E7ED84: zmsg_recv (zmsg.c:101) >> ==2874== by 0x401458: _recv_message (kt_server.c:114) >> >> _recv_message() is my function, snippet: >> >> zmsg_t *m = zmsg_recv(sock); >> assert(m); >> char *msgData = zframe_strdup(zmsg_pop(m)); >> zmsg_destroy(&m); >> free (msgData); >> >> >> So, I tracked this further down to zframe_new() which actually allocates >> sizeof(zframe_t) and later passes this to zmq_msg_init(). Since I work >> with a ZMQ_REP socket here, this must be in zmq::router_t::xrecv or more >> precisely in fq.recvpipe. recvpipe then calls zmq::msg_t::close. >> >> And this is where I suspect the memory leak to happen. The union-struct >> u defined in msg.hpp seems not to be freed correctly. But all this is >> massive speculation from my side — mostly because I'm just a >> beginner/noob and I have no clue about libzmq nor about C++. >> >> Let me know if I'm just a noob with no clue or I found something. :) >> >> Happy Hacking >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v2.0.21 (Darwin) >> >> iQIcBAEBAgAGBQJSOvXmAAoJEKkVOTYKXmyzs1gP/0lduRNVvjDe9Lf1H1kRZr4O >> RFqHWbfFxzEB3boLhpbvOE6mEedfPvyZnNeswm4pL4ROomRDABrJksxhEFGNAZqv >> nOk0lKwwouj6NwwfgiSasgprydsKfvfLAmvxSELP8yb7bJAKNg7P72Ec/lU1mIv+ >> kNbrMYG855awGUsJeOm1Y8c4nrJd/i7uc6U++bWu6u3yOQQDPP2gjpcdaaWIk47B >> GH/vZVfMmJjjB2QCcBnvaToQ2KiTPmr0JBOjgvMz6V3A1WXDYDwxZbxqt/ZJiptF >> AUCGY66gjK3fu9dyGmYEATN7P8bmLv99TzJ/ptHvQ1WDrsyyzDniumZ6yXyRhjKN >> lIvDqEdHH27xBGP5ml7UHCySMmyD+PGG1dPtijSd+0/YYey5/PcY809qaRbT6CKl >> XYzn3/HE5qPsKcPmriWm32Mk/1ujQfRGcdUemW0cHHL7Xa0F/R7NzVWr26hyDXt5 >> huyMaMURDD8aWf7qWQ+Iyz85PphO36InRShSS9FJT5jrqkOamwtrSJ5Z72as+bJ5 >> KbL9GowSE+tUyp2yDIIex5Ji6Rr7z8Kt8XRx9sh8+pnWcmVJwO53tkP1HqXVuoHm >> tlydMrxfneJPNnIF2vUTzjei1KEOed6QyQy8nZwGKFo3NspTTToZtxkTf/JiMbtE >> lNH7SzVoOJpa2+PftIBb >> =3xQ5 >> -----END PGP SIGNATURE----- >> _______________________________________________ >> zeromq-dev mailing list >> [email protected] >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
