0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 09:47:56 +08:00

Unnecessary dynamic memory allocation for zmq::socket_poller_t in zmq_poller_poll(). Fixed by allocating zmq::socket_poller_t from stack.

This commit is contained in:
bjovke 2017-04-04 11:51:59 +02:00
parent 5d5263ed8a
commit 319eb27f19

View File

@ -757,10 +757,9 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// implement zmq_poll on top of zmq_poller
int rc;
zmq_poller_event_t *events;
zmq::socket_poller_t poller;
events = new (std::nothrow) zmq_poller_event_t[nitems_];
alloc_assert(events);
void *poller = zmq_poller_new ();
alloc_assert(poller);
bool repeat_items = false;
// Register sockets with poller
@ -780,12 +779,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
}
}
if (modify) {
rc = zmq_poller_modify (poller, items_[i].socket, e);
rc = zmq_poller_modify (&poller, items_[i].socket, e);
} else {
rc = zmq_poller_add (poller, items_[i].socket, NULL, e);
rc = zmq_poller_add (&poller, items_[i].socket, NULL, e);
}
if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events;
return rc;
}
@ -800,12 +798,11 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
}
}
if (modify) {
rc = zmq_poller_modify_fd (poller, items_[i].fd, e);
rc = zmq_poller_modify_fd (&poller, items_[i].fd, e);
} else {
rc = zmq_poller_add_fd (poller, items_[i].fd, NULL, e);
rc = zmq_poller_add_fd (&poller, items_[i].fd, NULL, e);
}
if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events;
return rc;
}
@ -813,9 +810,8 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
}
// Wait for events
rc = zmq_poller_wait_all (poller, events, nitems_, timeout_);
rc = zmq_poller_wait_all (&poller, events, nitems_, timeout_);
if (rc < 0) {
zmq_poller_destroy (&poller);
delete [] events;
if (zmq_errno() == ETIMEDOUT) {
return 0;
@ -851,7 +847,6 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
}
// Cleanup
zmq_poller_destroy (&poller);
delete [] events;
return rc;
}