Memory leak in PUB/XPUB sockets fixed.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
Martin Sustrik 2011-02-26 08:42:20 +01:00
parent d4e418f5f4
commit 67b1f14190
4 changed files with 8 additions and 21 deletions

View File

@ -25,11 +25,10 @@
zmq::xpub_t::xpub_t (class ctx_t *parent_, uint32_t tid_) : zmq::xpub_t::xpub_t (class ctx_t *parent_, uint32_t tid_) :
socket_base_t (parent_, tid_), socket_base_t (parent_, tid_),
dist (this), dist (this)
fq (this)
{ {
options.type = ZMQ_XPUB; options.type = ZMQ_XPUB;
options.requires_in = true; options.requires_in = false;
options.requires_out = true; options.requires_out = true;
} }
@ -40,16 +39,14 @@ zmq::xpub_t::~xpub_t ()
void zmq::xpub_t::xattach_pipes (class reader_t *inpipe_, void zmq::xpub_t::xattach_pipes (class reader_t *inpipe_,
class writer_t *outpipe_, const blob_t &peer_identity_) class writer_t *outpipe_, const blob_t &peer_identity_)
{ {
zmq_assert (inpipe_ && outpipe_); zmq_assert (!inpipe_ && outpipe_);
dist.attach (outpipe_); dist.attach (outpipe_);
fq.attach (inpipe_);
} }
void zmq::xpub_t::process_term (int linger_) void zmq::xpub_t::process_term (int linger_)
{ {
// Terminate the outbound pipes. // Terminate the outbound pipes.
dist.terminate (); dist.terminate ();
fq.terminate ();
// Continue with the termination immediately. // Continue with the termination immediately.
socket_base_t::process_term (linger_); socket_base_t::process_term (linger_);
@ -67,11 +64,12 @@ bool zmq::xpub_t::xhas_out ()
int zmq::xpub_t::xrecv (zmq_msg_t *msg_, int flags_) int zmq::xpub_t::xrecv (zmq_msg_t *msg_, int flags_)
{ {
return fq.recv (msg_, flags_); errno = EAGAIN;
return -1;
} }
bool zmq::xpub_t::xhas_in () bool zmq::xpub_t::xhas_in ()
{ {
return fq.has_in (); return false;
} }

View File

@ -24,7 +24,6 @@
#include "array.hpp" #include "array.hpp"
#include "pipe.hpp" #include "pipe.hpp"
#include "dist.hpp" #include "dist.hpp"
#include "fq.hpp"
namespace zmq namespace zmq
{ {
@ -52,9 +51,6 @@ namespace zmq
// Distributor of messages holding the list of outbound pipes. // Distributor of messages holding the list of outbound pipes.
dist_t dist; dist_t dist;
// Fair queuer for inbound subscriptions.
fq_t fq;
xpub_t (const xpub_t&); xpub_t (const xpub_t&);
const xpub_t &operator = (const xpub_t&); const xpub_t &operator = (const xpub_t&);
}; };

View File

@ -27,13 +27,12 @@
zmq::xsub_t::xsub_t (class ctx_t *parent_, uint32_t tid_) : zmq::xsub_t::xsub_t (class ctx_t *parent_, uint32_t tid_) :
socket_base_t (parent_, tid_), socket_base_t (parent_, tid_),
fq (this), fq (this),
dist (this),
has_message (false), has_message (false),
more (false) more (false)
{ {
options.type = ZMQ_XSUB; options.type = ZMQ_XSUB;
options.requires_in = true; options.requires_in = true;
options.requires_out = true; options.requires_out = false;
zmq_msg_init (&message); zmq_msg_init (&message);
} }
@ -45,15 +44,13 @@ zmq::xsub_t::~xsub_t ()
void zmq::xsub_t::xattach_pipes (class reader_t *inpipe_, void zmq::xsub_t::xattach_pipes (class reader_t *inpipe_,
class writer_t *outpipe_, const blob_t &peer_identity_) class writer_t *outpipe_, const blob_t &peer_identity_)
{ {
zmq_assert (inpipe_ && outpipe_); zmq_assert (inpipe_ && !outpipe_);
fq.attach (inpipe_); fq.attach (inpipe_);
dist.attach (outpipe_);
} }
void zmq::xsub_t::process_term (int linger_) void zmq::xsub_t::process_term (int linger_)
{ {
fq.terminate (); fq.terminate ();
dist.terminate ();
socket_base_t::process_term (linger_); socket_base_t::process_term (linger_);
} }

View File

@ -24,7 +24,6 @@
#include "trie.hpp" #include "trie.hpp"
#include "socket_base.hpp" #include "socket_base.hpp"
#include "dist.hpp"
#include "fq.hpp" #include "fq.hpp"
namespace zmq namespace zmq
@ -58,9 +57,6 @@ namespace zmq
// Fair queueing object for inbound pipes. // Fair queueing object for inbound pipes.
fq_t fq; fq_t fq;
// Distributor mechanism for outbound messages (subscriptions).
dist_t dist;
// The repository of subscriptions. // The repository of subscriptions.
trie_t subscriptions; trie_t subscriptions;