[zeromq-dev] Bad Pointer Exception with ZMQ 2.2.X

Viviano, Aaron Aaron.Viviano at quadTechWorld.com
Fri Jul 20 00:31:52 CEST 2012


Hello ZeroMQ Devs,
I'm currently running into an issue with ZMQ, using CLRZMQ (Win7, VS2010), where it is crashing in the encoder::get_data function at this line:

memcpy (buffer + pos, write_pos, to_copy);

The variable write_pos would equal 0xfeeefeee, which according to what I've researched, means that the pointer was last touched by Window's HeapFree function [1]. Looking into the code I've found that this variable is set with the address from the msg_content_t::*data variable. This is then cleaned up in zmq_msg_close:

if (content->ffn)
    content->ffn (content->data, content->hint);
free (content);

I've attempted to add a function call in zmq::encoder_t::message_ready to a function called zmq_CheckForFreedData to try and fix the problem.

bool zmq_CheckForFreedData(zmq_msg_t *msg_)
{
       if (msg_->content == (zmq::msg_content_t*) ZMQ_VSM)
        return false;
       if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER)
        return false;

       if(((zmq::msg_content_t*) msg_->content)->data == (void *)0xfeeefeee)
       {
              return true;
       }
       return false;
}

...
if (!source || !source->read (&in_progress))
{
       zmq_msg_init (&in_progress);
       return false;
}
else if(zmq_CheckForFreedData(&in_progress))
{
       zmq_msg_init (&in_progress);
       return false;
}
...

While this prevents the crash I'm now seeing my  program lock up. At the moment I don't have a simple test program for you, however, until I have the chance to put one together, what would be the best place to start looking for why this error is happening in the code?

Thank you,
Aaron


1.       http://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120719/3e0cac1f/attachment.htm>


More information about the zeromq-dev mailing list