From 53fb12068729482ac4cd127bb6f0fe9ab656b5c9 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 28 Sep 2016 15:17:57 +0200 Subject: [PATCH] heap-allocate events in zmq_poller_poll variable-size array allocation is not allowed by some compilers --- src/zmq.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/zmq.cpp b/src/zmq.cpp index 23a3d6ab..0db3a884 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -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 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 (); alloc_assert(poller); - + // Register sockets with poller for (int i = 0; i < nitems_; i++) { if (items_[i].socket) { @@ -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); if (rc < 0) { zmq_poller_destroy (&poller); + delete [] events; return rc; } } else { @@ -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); if (rc < 0) { zmq_poller_destroy (&poller); + delete [] events; return rc; } } @@ -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_); if (rc < 0) { zmq_poller_destroy (&poller); + delete [] events; return rc; } @@ -784,6 +789,7 @@ inline int zmq_poller_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) // Cleanup rc = zmq_poller_destroy (&poller); + delete [] events; return rc; } #endif // ZMQ_HAVE_POLLER