Commit 53fb1206 authored by Min RK's avatar Min RK

heap-allocate events in zmq_poller_poll

variable-size array allocation is not allowed by some compilers
parent 55930f5e
...@@ -747,10 +747,12 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -747,10 +747,12 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
{ {
// implement zmq_poll on top of zmq_poller // implement zmq_poll on top of zmq_poller
int rc; int rc;
zmq_poller_event_t events[nitems_]; zmq_poller_event_t *events;
events = new zmq_poller_event_t[nitems_];
alloc_assert(events);
void *poller = zmq_poller_new (); void *poller = zmq_poller_new ();
alloc_assert(poller); alloc_assert(poller);
// Register sockets with poller // Register sockets with poller
for (int i = 0; i < nitems_; i++) { for (int i = 0; i < nitems_; i++) {
if (items_[i].socket) { if (items_[i].socket) {
...@@ -758,6 +760,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -758,6 +760,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
rc = zmq_poller_add (poller, items_[i].socket, NULL, items_[i].events); rc = zmq_poller_add (poller, items_[i].socket, NULL, items_[i].events);
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller); zmq_poller_destroy (&poller);
delete [] events;
return rc; return rc;
} }
} else { } else {
...@@ -765,6 +768,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -765,6 +768,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
rc = zmq_poller_add_fd (poller, items_[i].fd, NULL, items_[i].events); rc = zmq_poller_add_fd (poller, items_[i].fd, NULL, items_[i].events);
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller); zmq_poller_destroy (&poller);
delete [] events;
return rc; return rc;
} }
} }
...@@ -774,6 +778,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -774,6 +778,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
rc = zmq_poller_wait_all (poller, events, nitems_, timeout_); rc = zmq_poller_wait_all (poller, events, nitems_, timeout_);
if (rc < 0) { if (rc < 0) {
zmq_poller_destroy (&poller); zmq_poller_destroy (&poller);
delete [] events;
return rc; return rc;
} }
...@@ -784,6 +789,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) ...@@ -784,6 +789,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// Cleanup // Cleanup
rc = zmq_poller_destroy (&poller); rc = zmq_poller_destroy (&poller);
delete [] events;
return rc; return rc;
} }
#endif // ZMQ_HAVE_POLLER #endif // ZMQ_HAVE_POLLER
......
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