Commit d4e418f5 authored by Martin Sustrik's avatar Martin Sustrik

Socket with no owner objects is deallocated immediately

Till now the deallocation of such socket was delayed
till zmq_term() thus creating a "leak".
Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent c22e5273
...@@ -96,12 +96,13 @@ void zmq::reaper_t::process_stop () ...@@ -96,12 +96,13 @@ void zmq::reaper_t::process_stop ()
void zmq::reaper_t::process_reap (socket_base_t *socket_) void zmq::reaper_t::process_reap (socket_base_t *socket_)
{ {
// Start termination of associated I/O object hierarchy.
socket_->terminate ();
// Add the socket to the poller. // Add the socket to the poller.
socket_->start_reaping (poller); socket_->start_reaping (poller);
// Start termination of associated I/O object hierarchy.
socket_->terminate ();
socket_->check_destroy ();
++sockets; ++sockets;
} }
......
...@@ -754,7 +754,21 @@ void zmq::socket_base_t::in_event () ...@@ -754,7 +754,21 @@ void zmq::socket_base_t::in_event ()
// Process any commands from other threads/sockets that may be available // Process any commands from other threads/sockets that may be available
// at the moment. Ultimately, socket will be destroyed. // at the moment. Ultimately, socket will be destroyed.
process_commands (false, false); process_commands (false, false);
check_destroy ();
}
void zmq::socket_base_t::out_event ()
{
zmq_assert (false);
}
void zmq::socket_base_t::timer_event (int id_)
{
zmq_assert (false);
}
void zmq::socket_base_t::check_destroy ()
{
// If the object was already marked as destroyed, finish the deallocation. // If the object was already marked as destroyed, finish the deallocation.
if (destroyed) { if (destroyed) {
...@@ -771,13 +785,3 @@ void zmq::socket_base_t::in_event () ...@@ -771,13 +785,3 @@ void zmq::socket_base_t::in_event ()
own_t::process_destroy (); own_t::process_destroy ();
} }
} }
void zmq::socket_base_t::out_event ()
{
zmq_assert (false);
}
void zmq::socket_base_t::timer_event (int id_)
{
zmq_assert (false);
}
...@@ -97,6 +97,10 @@ namespace zmq ...@@ -97,6 +97,10 @@ namespace zmq
void out_event (); void out_event ();
void timer_event (int id_); void timer_event (int id_);
// To be called after processing commands or invoking any command
// handlers explicitly. If required, it will deallocate the socket.
void check_destroy ();
protected: protected:
socket_base_t (class ctx_t *parent_, uint32_t tid_); socket_base_t (class ctx_t *parent_, uint32_t tid_);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment