Commit 6d9eb184 authored by Constantin Rack's avatar Constantin Rack

Merge pull request #1530 from reza-ebrahimi/master

define a macro for heap object deletion in a unified manner (related …
parents 9bf88bcc 1621c25e
...@@ -503,6 +503,9 @@ ZMQ_EXPORT void zmq_threadclose (void* thread); ...@@ -503,6 +503,9 @@ ZMQ_EXPORT void zmq_threadclose (void* thread);
/******************************************************************************/ /******************************************************************************/
#define ZMQ_UNUSED(object) (void)object #define ZMQ_UNUSED(object) (void)object
#define LIBZMQ_DELETE(p_object) \
delete p_object; \
p_object = 0;
#undef ZMQ_EXPORT #undef ZMQ_EXPORT
......
...@@ -49,16 +49,14 @@ zmq::address_t::~address_t () ...@@ -49,16 +49,14 @@ zmq::address_t::~address_t ()
{ {
if (protocol == "tcp") { if (protocol == "tcp") {
if (resolved.tcp_addr) { if (resolved.tcp_addr) {
delete resolved.tcp_addr; LIBZMQ_DELETE(resolved.tcp_addr);
resolved.tcp_addr = 0;
} }
} }
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
else else
if (protocol == "ipc") { if (protocol == "ipc") {
if (resolved.ipc_addr) { if (resolved.ipc_addr) {
delete resolved.ipc_addr; LIBZMQ_DELETE(resolved.ipc_addr);
resolved.ipc_addr = 0;
} }
} }
#endif #endif
...@@ -66,8 +64,7 @@ zmq::address_t::~address_t () ...@@ -66,8 +64,7 @@ zmq::address_t::~address_t ()
else else
if (protocol == "tipc") { if (protocol == "tipc") {
if (resolved.tipc_addr) { if (resolved.tipc_addr) {
delete resolved.tipc_addr; LIBZMQ_DELETE(resolved.tipc_addr);
resolved.tipc_addr = 0;
} }
} }
#endif #endif
......
...@@ -97,15 +97,17 @@ zmq::ctx_t::~ctx_t () ...@@ -97,15 +97,17 @@ zmq::ctx_t::~ctx_t ()
// Ask I/O threads to terminate. If stop signal wasn't sent to I/O // Ask I/O threads to terminate. If stop signal wasn't sent to I/O
// thread subsequent invocation of destructor would hang-up. // thread subsequent invocation of destructor would hang-up.
for (io_threads_t::size_type i = 0; i != io_threads.size (); i++) for (io_threads_t::size_type i = 0; i != io_threads.size (); i++) {
io_threads [i]->stop (); io_threads [i]->stop ();
}
// Wait till I/O threads actually terminate. // Wait till I/O threads actually terminate.
for (io_threads_t::size_type i = 0; i != io_threads.size (); i++) for (io_threads_t::size_type i = 0; i != io_threads.size (); i++) {
delete io_threads [i]; LIBZMQ_DELETE(io_threads [i]);
}
// Deallocate the reaper thread object. // Deallocate the reaper thread object.
delete reaper; LIBZMQ_DELETE(reaper);
// Deallocate the array of mailboxes. No special work is // Deallocate the array of mailboxes. No special work is
// needed as mailboxes themselves were deallocated with their // needed as mailboxes themselves were deallocated with their
......
...@@ -56,8 +56,9 @@ zmq::epoll_t::~epoll_t () ...@@ -56,8 +56,9 @@ zmq::epoll_t::~epoll_t ()
worker.stop (); worker.stop ();
close (epoll_fd); close (epoll_fd);
for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
delete *it; LIBZMQ_DELETE(*it);
}
} }
zmq::epoll_t::handle_t zmq::epoll_t::add_fd (fd_t fd_, i_poll_events *events_) zmq::epoll_t::handle_t zmq::epoll_t::add_fd (fd_t fd_, i_poll_events *events_)
...@@ -177,9 +178,9 @@ void zmq::epoll_t::loop () ...@@ -177,9 +178,9 @@ void zmq::epoll_t::loop ()
} }
// Destroy retired event sources. // Destroy retired event sources.
for (retired_t::iterator it = retired.begin (); it != retired.end (); for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
++it) LIBZMQ_DELETE(*it);
delete *it; }
retired.clear (); retired.clear ();
} }
} }
......
...@@ -46,7 +46,7 @@ zmq::io_thread_t::io_thread_t (ctx_t *ctx_, uint32_t tid_) : ...@@ -46,7 +46,7 @@ zmq::io_thread_t::io_thread_t (ctx_t *ctx_, uint32_t tid_) :
zmq::io_thread_t::~io_thread_t () zmq::io_thread_t::~io_thread_t ()
{ {
delete poller; LIBZMQ_DELETE(poller);
} }
void zmq::io_thread_t::start () void zmq::io_thread_t::start ()
......
...@@ -210,9 +210,9 @@ void zmq::kqueue_t::loop () ...@@ -210,9 +210,9 @@ void zmq::kqueue_t::loop ()
} }
// Destroy retired event sources. // Destroy retired event sources.
for (retired_t::iterator it = retired.begin (); it != retired.end (); for (retired_t::iterator it = retired.begin (); it != retired.end (); ++it) {
++it) LIBZMQ_DELETE(*it);
delete *it; }
retired.clear (); retired.clear ();
} }
} }
......
...@@ -235,9 +235,11 @@ int zmq::msg_t::close () ...@@ -235,9 +235,11 @@ int zmq::msg_t::close ()
} }
} }
if (u.base.metadata != NULL) if (u.base.metadata != NULL) {
if (u.base.metadata->drop_ref ()) if (u.base.metadata->drop_ref ()) {
delete u.base.metadata; LIBZMQ_DELETE(u.base.metadata);
}
}
// Make the message invalid. // Make the message invalid.
u.base.type = 0; u.base.type = 0;
...@@ -392,8 +394,7 @@ void zmq::msg_t::reset_metadata () ...@@ -392,8 +394,7 @@ void zmq::msg_t::reset_metadata ()
{ {
if (u.base.metadata) { if (u.base.metadata) {
if (u.base.metadata->drop_ref ()) if (u.base.metadata->drop_ref ())
delete u.base.metadata; LIBZMQ_DELETE(u.base.metadata);
u.base.metadata = NULL;
} }
} }
......
...@@ -52,19 +52,17 @@ zmq::mtrie_t::mtrie_t () : ...@@ -52,19 +52,17 @@ zmq::mtrie_t::mtrie_t () :
zmq::mtrie_t::~mtrie_t () zmq::mtrie_t::~mtrie_t ()
{ {
if (pipes) { if (pipes) {
delete pipes; LIBZMQ_DELETE(pipes);
pipes = 0;
} }
if (count == 1) { if (count == 1) {
zmq_assert (next.node); zmq_assert (next.node);
delete next.node; LIBZMQ_DELETE(next.node);
next.node = 0;
} }
else else if (count > 1) {
if (count > 1) { for (unsigned short i = 0; i != count; ++i) {
for (unsigned short i = 0; i != count; ++i) LIBZMQ_DELETE(next.table[i]);
delete next.table [i]; }
free (next.table); free (next.table);
} }
} }
...@@ -178,8 +176,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_, ...@@ -178,8 +176,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
} }
if (pipes->empty ()) { if (pipes->empty ()) {
delete pipes; LIBZMQ_DELETE(pipes);
pipes = 0;
} }
} }
...@@ -203,8 +200,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_, ...@@ -203,8 +200,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
// Prune the node if it was made redundant by the removal // Prune the node if it was made redundant by the removal
if (next.node->is_redundant ()) { if (next.node->is_redundant ()) {
delete next.node; LIBZMQ_DELETE(next.node);
next.node = 0;
count = 0; count = 0;
--live_nodes; --live_nodes;
zmq_assert (live_nodes == 0); zmq_assert (live_nodes == 0);
...@@ -226,8 +222,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_, ...@@ -226,8 +222,7 @@ void zmq::mtrie_t::rm_helper (pipe_t *pipe_, unsigned char **buff_,
// Prune redundant nodes from the mtrie // Prune redundant nodes from the mtrie
if (next.table [c]->is_redundant ()) { if (next.table [c]->is_redundant ()) {
delete next.table [c]; LIBZMQ_DELETE(next.table[c]);
next.table [c] = 0;
zmq_assert (live_nodes > 0); zmq_assert (live_nodes > 0);
--live_nodes; --live_nodes;
...@@ -306,8 +301,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_, ...@@ -306,8 +301,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
pipes_t::size_type erased = pipes->erase (pipe_); pipes_t::size_type erased = pipes->erase (pipe_);
zmq_assert (erased == 1); zmq_assert (erased == 1);
if (pipes->empty ()) { if (pipes->empty ()) {
delete pipes; LIBZMQ_DELETE(pipes);
pipes = 0;
} }
} }
return !pipes; return !pipes;
...@@ -326,7 +320,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_, ...@@ -326,7 +320,7 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
bool ret = next_node->rm_helper (prefix_ + 1, size_ - 1, pipe_); bool ret = next_node->rm_helper (prefix_ + 1, size_ - 1, pipe_);
if (next_node->is_redundant ()) { if (next_node->is_redundant ()) {
delete next_node; LIBZMQ_DELETE(next_node);
zmq_assert (count > 0); zmq_assert (count > 0);
if (count == 1) { if (count == 1) {
......
...@@ -89,8 +89,9 @@ void zmq::pgm_receiver_t::unplug () ...@@ -89,8 +89,9 @@ void zmq::pgm_receiver_t::unplug ()
{ {
// Delete decoders. // Delete decoders.
for (peers_t::iterator it = peers.begin (); it != peers.end (); ++it) { for (peers_t::iterator it = peers.begin (); it != peers.end (); ++it) {
if (it->second.decoder != NULL) if (it->second.decoder != NULL) {
delete it->second.decoder; LIBZMQ_DELETE(it->second.decoder);
}
} }
peers.clear (); peers.clear ();
active_tsi = NULL; active_tsi = NULL;
...@@ -141,8 +142,7 @@ void zmq::pgm_receiver_t::restart_input () ...@@ -141,8 +142,7 @@ void zmq::pgm_receiver_t::restart_input ()
// Data error. Delete message decoder, mark the // Data error. Delete message decoder, mark the
// peer as not joined and drop remaining data. // peer as not joined and drop remaining data.
it->second.joined = false; it->second.joined = false;
delete it->second.decoder; LIBZMQ_DELETE(it->second.decoder);
it->second.decoder = NULL;
insize = 0; insize = 0;
} }
} }
...@@ -194,8 +194,7 @@ void zmq::pgm_receiver_t::in_event () ...@@ -194,8 +194,7 @@ void zmq::pgm_receiver_t::in_event ()
if (it != peers.end ()) { if (it != peers.end ()) {
it->second.joined = false; it->second.joined = false;
if (it->second.decoder != NULL) { if (it->second.decoder != NULL) {
delete it->second.decoder; LIBZMQ_DELETE(it->second.decoder);
it->second.decoder = NULL;
} }
} }
break; break;
...@@ -252,8 +251,7 @@ void zmq::pgm_receiver_t::in_event () ...@@ -252,8 +251,7 @@ void zmq::pgm_receiver_t::in_event ()
} }
it->second.joined = false; it->second.joined = false;
delete it->second.decoder; LIBZMQ_DELETE(it->second.decoder);
it->second.decoder = NULL;
insize = 0; insize = 0;
} }
} }
......
...@@ -284,7 +284,7 @@ void zmq::pipe_t::process_hiccup (void *pipe_) ...@@ -284,7 +284,7 @@ void zmq::pipe_t::process_hiccup (void *pipe_)
int rc = msg.close (); int rc = msg.close ();
errno_assert (rc == 0); errno_assert (rc == 0);
} }
delete outpipe; LIBZMQ_DELETE(outpipe);
// Plug in the new outpipe. // Plug in the new outpipe.
zmq_assert (pipe_); zmq_assert (pipe_);
...@@ -368,7 +368,7 @@ void zmq::pipe_t::process_pipe_term_ack () ...@@ -368,7 +368,7 @@ void zmq::pipe_t::process_pipe_term_ack ()
} }
} }
delete inpipe; LIBZMQ_DELETE(inpipe);
// Deallocate the pipe object // Deallocate the pipe object
delete this; delete this;
...@@ -385,49 +385,41 @@ void zmq::pipe_t::terminate (bool delay_) ...@@ -385,49 +385,41 @@ void zmq::pipe_t::terminate (bool delay_)
delay = delay_; delay = delay_;
// If terminate was already called, we can ignore the duplicit invocation. // If terminate was already called, we can ignore the duplicit invocation.
if (state == term_req_sent1 || state == term_req_sent2) if (state == term_req_sent1 || state == term_req_sent2) {
return; return;
}
// If the pipe is in the final phase of async termination, it's going to // If the pipe is in the final phase of async termination, it's going to
// closed anyway. No need to do anything special here. // closed anyway. No need to do anything special here.
else else if (state == term_ack_sent) {
if (state == term_ack_sent)
return; return;
}
// The simple sync termination case. Ask the peer to terminate and wait // The simple sync termination case. Ask the peer to terminate and wait
// for the ack. // for the ack.
else else if (state == active) {
if (state == active) {
send_pipe_term (peer); send_pipe_term (peer);
state = term_req_sent1; state = term_req_sent1;
} }
// There are still pending messages available, but the user calls // There are still pending messages available, but the user calls
// 'terminate'. We can act as if all the pending messages were read. // 'terminate'. We can act as if all the pending messages were read.
else else if (state == waiting_for_delimiter && !delay) {
if (state == waiting_for_delimiter && !delay) {
outpipe = NULL; outpipe = NULL;
send_pipe_term_ack (peer); send_pipe_term_ack (peer);
state = term_ack_sent; state = term_ack_sent;
} }
// If there are pending messages still available, do nothing. // If there are pending messages still available, do nothing.
else else if (state == waiting_for_delimiter) {
if (state == waiting_for_delimiter) {
} }
// We've already got delimiter, but not term command yet. We can ignore // We've already got delimiter, but not term command yet. We can ignore
// the delimiter and ack synchronously terminate as if we were in // the delimiter and ack synchronously terminate as if we were in
// active state. // active state.
else else if (state == delimiter_received) {
if (state == delimiter_received) {
send_pipe_term (peer); send_pipe_term (peer);
state = term_req_sent1; state = term_req_sent1;
} }
// There are no other states. // There are no other states.
else else {
zmq_assert (false); zmq_assert (false);
}
// Stop outbound flow of messages. // Stop outbound flow of messages.
out_active = false; out_active = false;
...@@ -505,11 +497,9 @@ void zmq::pipe_t::hiccup () ...@@ -505,11 +497,9 @@ void zmq::pipe_t::hiccup ()
// Create new inpipe. // Create new inpipe.
if (conflate) if (conflate)
inpipe = new (std::nothrow) inpipe = new (std::nothrow)ypipe_conflate_t <msg_t>();
ypipe_conflate_t <msg_t> ();
else else
inpipe = new (std::nothrow) inpipe = new (std::nothrow)ypipe_t <msg_t, message_pipe_granularity>();
ypipe_t <msg_t, message_pipe_granularity> ();
alloc_assert (inpipe); alloc_assert (inpipe);
in_active = true; in_active = true;
......
...@@ -49,7 +49,7 @@ zmq::reaper_t::reaper_t (class ctx_t *ctx_, uint32_t tid_) : ...@@ -49,7 +49,7 @@ zmq::reaper_t::reaper_t (class ctx_t *ctx_, uint32_t tid_) :
zmq::reaper_t::~reaper_t () zmq::reaper_t::~reaper_t ()
{ {
delete poller; LIBZMQ_DELETE(poller);
} }
zmq::mailbox_t *zmq::reaper_t::get_mailbox () zmq::mailbox_t *zmq::reaper_t::get_mailbox ()
......
...@@ -111,7 +111,7 @@ zmq::session_base_t::~session_base_t () ...@@ -111,7 +111,7 @@ zmq::session_base_t::~session_base_t ()
if (engine) if (engine)
engine->terminate (); engine->terminate ();
delete addr; LIBZMQ_DELETE(addr);
} }
void zmq::session_base_t::attach_pipe (pipe_t *pipe_) void zmq::session_base_t::attach_pipe (pipe_t *pipe_)
......
...@@ -156,7 +156,7 @@ zmq::socket_base_t *zmq::socket_base_t::create (int type_, class ctx_t *parent_, ...@@ -156,7 +156,7 @@ zmq::socket_base_t *zmq::socket_base_t::create (int type_, class ctx_t *parent_,
if (mailbox != NULL && mailbox->get_fd () == retired_fd) { if (mailbox != NULL && mailbox->get_fd () == retired_fd) {
s->destroyed = true; s->destroyed = true;
delete s; LIBZMQ_DELETE(s);
return NULL; return NULL;
} }
...@@ -189,10 +189,11 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool ...@@ -189,10 +189,11 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool
zmq::socket_base_t::~socket_base_t () zmq::socket_base_t::~socket_base_t ()
{ {
delete mailbox; LIBZMQ_DELETE(mailbox);
if (reaper_signaler) if (reaper_signaler) {
delete reaper_signaler; LIBZMQ_DELETE(reaper_signaler);
}
stop_monitor (); stop_monitor ();
zmq_assert (destroyed); zmq_assert (destroyed);
...@@ -535,7 +536,7 @@ int zmq::socket_base_t::bind (const char *addr_) ...@@ -535,7 +536,7 @@ int zmq::socket_base_t::bind (const char *addr_)
alloc_assert (listener); alloc_assert (listener);
int rc = listener->set_address (address.c_str ()); int rc = listener->set_address (address.c_str ());
if (rc != 0) { if (rc != 0) {
delete listener; LIBZMQ_DELETE(listener);
event_bind_failed (address, zmq_errno()); event_bind_failed (address, zmq_errno());
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
...@@ -557,7 +558,7 @@ int zmq::socket_base_t::bind (const char *addr_) ...@@ -557,7 +558,7 @@ int zmq::socket_base_t::bind (const char *addr_)
alloc_assert (listener); alloc_assert (listener);
int rc = listener->set_address (address.c_str ()); int rc = listener->set_address (address.c_str ());
if (rc != 0) { if (rc != 0) {
delete listener; LIBZMQ_DELETE(listener);
event_bind_failed (address, zmq_errno()); event_bind_failed (address, zmq_errno());
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
...@@ -579,7 +580,7 @@ int zmq::socket_base_t::bind (const char *addr_) ...@@ -579,7 +580,7 @@ int zmq::socket_base_t::bind (const char *addr_)
alloc_assert (listener); alloc_assert (listener);
int rc = listener->set_address (address.c_str ()); int rc = listener->set_address (address.c_str ());
if (rc != 0) { if (rc != 0) {
delete listener; LIBZMQ_DELETE(listener);
event_bind_failed (address, zmq_errno()); event_bind_failed (address, zmq_errno());
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
...@@ -788,7 +789,7 @@ int zmq::socket_base_t::connect (const char *addr_) ...@@ -788,7 +789,7 @@ int zmq::socket_base_t::connect (const char *addr_)
} }
if (rc == -1) { if (rc == -1) {
errno = EINVAL; errno = EINVAL;
delete paddr; LIBZMQ_DELETE(paddr);
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
} }
...@@ -802,7 +803,7 @@ int zmq::socket_base_t::connect (const char *addr_) ...@@ -802,7 +803,7 @@ int zmq::socket_base_t::connect (const char *addr_)
alloc_assert (paddr->resolved.ipc_addr); alloc_assert (paddr->resolved.ipc_addr);
int rc = paddr->resolved.ipc_addr->resolve (address.c_str ()); int rc = paddr->resolved.ipc_addr->resolve (address.c_str ());
if (rc != 0) { if (rc != 0) {
delete paddr; LIBZMQ_DELETE(paddr);
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
} }
...@@ -831,7 +832,7 @@ int zmq::socket_base_t::connect (const char *addr_) ...@@ -831,7 +832,7 @@ int zmq::socket_base_t::connect (const char *addr_)
alloc_assert (paddr->resolved.tipc_addr); alloc_assert (paddr->resolved.tipc_addr);
int rc = paddr->resolved.tipc_addr->resolve (address.c_str()); int rc = paddr->resolved.tipc_addr->resolve (address.c_str());
if (rc != 0) { if (rc != 0) {
delete paddr; LIBZMQ_DELETE(paddr);
EXIT_MUTEX(); EXIT_MUTEX();
return -1; return -1;
} }
......
...@@ -72,7 +72,7 @@ zmq::socks_connecter_t::socks_connecter_t (class io_thread_t *io_thread_, ...@@ -72,7 +72,7 @@ zmq::socks_connecter_t::socks_connecter_t (class io_thread_t *io_thread_,
zmq::socks_connecter_t::~socks_connecter_t () zmq::socks_connecter_t::~socks_connecter_t ()
{ {
zmq_assert (s == retired_fd); zmq_assert (s == retired_fd);
delete proxy_addr; LIBZMQ_DELETE(proxy_addr);
} }
void zmq::socks_connecter_t::process_plug () void zmq::socks_connecter_t::process_plug ()
...@@ -303,15 +303,14 @@ int zmq::socks_connecter_t::connect_to_proxy () ...@@ -303,15 +303,14 @@ int zmq::socks_connecter_t::connect_to_proxy ()
zmq_assert (s == retired_fd); zmq_assert (s == retired_fd);
// Resolve the address // Resolve the address
delete proxy_addr->resolved.tcp_addr; LIBZMQ_DELETE(proxy_addr->resolved.tcp_addr);
proxy_addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t (); proxy_addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
alloc_assert (proxy_addr->resolved.tcp_addr); alloc_assert (proxy_addr->resolved.tcp_addr);
int rc = proxy_addr->resolved.tcp_addr->resolve ( int rc = proxy_addr->resolved.tcp_addr->resolve (
proxy_addr->address.c_str (), false, options.ipv6); proxy_addr->address.c_str (), false, options.ipv6);
if (rc != 0) { if (rc != 0) {
delete proxy_addr->resolved.tcp_addr; LIBZMQ_DELETE(proxy_addr->resolved.tcp_addr);
proxy_addr->resolved.tcp_addr = NULL;
return -1; return -1;
} }
zmq_assert (proxy_addr->resolved.tcp_addr != NULL); zmq_assert (proxy_addr->resolved.tcp_addr != NULL);
......
...@@ -172,13 +172,15 @@ zmq::stream_engine_t::~stream_engine_t () ...@@ -172,13 +172,15 @@ zmq::stream_engine_t::~stream_engine_t ()
// Drop reference to metadata and destroy it if we are // Drop reference to metadata and destroy it if we are
// the only user. // the only user.
if (metadata != NULL) if (metadata != NULL) {
if (metadata->drop_ref ()) if (metadata->drop_ref ()) {
delete metadata; LIBZMQ_DELETE(metadata);
}
}
delete encoder; LIBZMQ_DELETE(encoder);
delete decoder; LIBZMQ_DELETE(decoder);
delete mechanism; LIBZMQ_DELETE(mechanism);
} }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, void zmq::stream_engine_t::plug (io_thread_t *io_thread_,
......
...@@ -252,8 +252,7 @@ int zmq::tcp_connecter_t::open () ...@@ -252,8 +252,7 @@ int zmq::tcp_connecter_t::open ()
// Resolve the address // Resolve the address
if (addr->resolved.tcp_addr != NULL) { if (addr->resolved.tcp_addr != NULL) {
delete addr->resolved.tcp_addr; LIBZMQ_DELETE(addr->resolved.tcp_addr);
addr->resolved.tcp_addr = NULL;
} }
addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t (); addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
...@@ -261,8 +260,7 @@ int zmq::tcp_connecter_t::open () ...@@ -261,8 +260,7 @@ int zmq::tcp_connecter_t::open ()
int rc = addr->resolved.tcp_addr->resolve ( int rc = addr->resolved.tcp_addr->resolve (
addr->address.c_str (), false, options.ipv6); addr->address.c_str (), false, options.ipv6);
if (rc != 0) { if (rc != 0) {
delete addr->resolved.tcp_addr; LIBZMQ_DELETE(addr->resolved.tcp_addr);
addr->resolved.tcp_addr = NULL;
return -1; return -1;
} }
zmq_assert (addr->resolved.tcp_addr != NULL); zmq_assert (addr->resolved.tcp_addr != NULL);
......
...@@ -52,13 +52,12 @@ zmq::trie_t::~trie_t () ...@@ -52,13 +52,12 @@ zmq::trie_t::~trie_t ()
{ {
if (count == 1) { if (count == 1) {
zmq_assert (next.node); zmq_assert (next.node);
delete next.node; LIBZMQ_DELETE(next.node);
next.node = 0;
} }
else else if (count > 1) {
if (count > 1) { for (unsigned short i = 0; i != count; ++i) {
for (unsigned short i = 0; i != count; ++i) LIBZMQ_DELETE(next.table[i]);
delete next.table [i]; }
free (next.table); free (next.table);
} }
} }
...@@ -165,7 +164,7 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_) ...@@ -165,7 +164,7 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_)
// Prune redundant nodes // Prune redundant nodes
if (next_node->is_redundant ()) { if (next_node->is_redundant ()) {
delete next_node; LIBZMQ_DELETE(next_node);
zmq_assert (count > 0); zmq_assert (count > 0);
if (count == 1) { if (count == 1) {
......
...@@ -721,7 +721,7 @@ void *zmq_poller_new () ...@@ -721,7 +721,7 @@ void *zmq_poller_new ()
int zmq_poller_close (void* p) int zmq_poller_close (void* p)
{ {
zmq::signaler_t *s = (zmq::signaler_t*)p; zmq::signaler_t *s = (zmq::signaler_t*)p;
delete s; LIBZMQ_DELETE(s);
return 0; return 0;
} }
......
...@@ -88,7 +88,7 @@ void zmq_threadclose(void* thread) ...@@ -88,7 +88,7 @@ void zmq_threadclose(void* thread)
{ {
zmq::thread_t* pThread = static_cast<zmq::thread_t*>(thread); zmq::thread_t* pThread = static_cast<zmq::thread_t*>(thread);
pThread->stop(); pThread->stop();
delete pThread; LIBZMQ_DELETE(pThread);
} }
// Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding // Z85 codec, taken from 0MQ RFC project, implements RFC32 Z85 encoding
......
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