title: pyzmq Segmentation fault on large .recv()
body: <ul>
  <li>edited - I think I wrongly pointed the blame at pyzmq - I actually was running in a QThread and upon suggestion worked on a full working example - not using QThread and I do not see any issues.  I'm going to drop my working example for anyone who may want to reference this example. </li>
  </ul>
  
  <p>I'm attempting to publish data on a <strong><code>pyzmq</code></strong> socket.  I have experience here but never for larger data. On occasion, I'm getting a seg fault or at other times a message about <strong><code>free()</code></strong>.  This happens more often for larger data sets, up to a point where it never actually works (depending on size).  </p>
  
  <p>subscriber code:</p>
  
  <pre><code>import zmq
  from time import sleep
  from threading import Thread
  
  class ZmqListener(Thread):
      def __init__(self, addr, port):
          Thread.__init__(self)
          self.addr = addr
          self.port = port
  
      def run(self):
          socket = zmq.Context().socket(zmq.SUB)
          socket.connect("tcp://%s:%s" % (self.addr, self.port))
          socket.setsockopt(zmq.SUBSCRIBE, "test:".encode('utf-8'))
          poller = zmq.Poller()
          poller.register(socket, zmq.POLLIN)
          self.running = True
          while self.running:
              print(socket.recv())
              s = dict(poller.poll(1000))
              if s:
                  if s.get(socket) == zmq.POLLIN:
                      msg = socket.recv()
                      print(msg)
          socket.close()
  
  th = ZmqListener('localhost', IMG_BASE_PORT)
  th.start()
  
  while True:
      try:
          sleep(1)
      except KeyboardInterrupt:
          break
  
  th.running = False
  th.join()
  </code></pre>
  
  <p>QThread subscriber code that breaks at random:</p>
  
  <pre><code>class ZmqListener(QtCore.QThread):
  
      message = QtCore.Signal(object)
  
      def __init__(self, addr, port, parent=None):
          QtCore.QThread.__init__(self, parent)
          self.addr = addr
          self.port = port
  
      def run(self):
          socket = zmq.Context().socket(zmq.SUB)
          socket.connect("tcp://%s:%s" % (self.addr, self.port))
          socket.setsockopt(zmq.SUBSCRIBE, "{}:".format(IMG_SUBS_HEAD).encode('utf-8'))
          poller = zmq.Poller()
          poller.register(socket, zmq.POLLIN)
          self.running = True
          while self.running:
              s = dict(poller.poll(1000))
              if s:
                  if s.get(socket) == zmq.POLLIN:
                      msg = socket.recv()
                      self.message.emit(msg[len(IMG_SUBS_HEAD)+1::])
          socket.close()
  </code></pre>
  
  <p>publisher code:</p>
  
  <pre><code>#include &lt;zmq.hpp&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ios&gt;
  #include &lt;thread&gt;
  #include &lt;chrono&gt;
  
  #define PORT 13600
  #define PUBS "test:"
  #define NBYT 256 * 1024 * 1024 * 1024
  
  int main()
  {
    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_PUB);
    std::string rep_head;
    char bytes[NBYT];
  
    std::string zaddr("tcp://*:");
    zaddr += std::to_string(PORT);
    socket.bind(zaddr.c_str());
  
    rep_head = std::string(PUBS);
  
    int idx = 0;
    while (1) {
      for (int i = 0; i &lt; NBYT; i++)
        bytes[i] = rand();   // sleazy                                                                            
      std::stringstream ss;
      ss &lt;&lt; rep_head &lt;&lt; std::hex &lt;&lt; (int)idx &lt;&lt; ":";
      zmq::message_t msg(ss.str().length() + NBYT);
      memcpy((char*)msg.data(), ss.str().data(), ss.str().length());
      memcpy(((char*)msg.data())+ss.str().length(), bytes, NBYT);
      socket.send(msg);
      std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
  
    socket.close();
  
    return 0;
  }
  </code></pre>
  
  <p>I've recently updated my OS (Ubuntu 18.04) and this was not a problem in the past.</p>