Commit cafcdbbe authored by Martin Sustrik's avatar Martin Sustrik

Safety measure in zmq_msg_close implemented

zmq_msg_close now empties the message on zmq_msg_close, thus not
leaving random data in the structure, that may be mistaken for
a valid message.
Signed-off-by: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent b174ad2c
...@@ -154,9 +154,8 @@ int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_, ...@@ -154,9 +154,8 @@ int zmq_msg_init_data (zmq_msg_t *msg_, void *data_, size_t size_,
int zmq_msg_close (zmq_msg_t *msg_) int zmq_msg_close (zmq_msg_t *msg_)
{ {
// For VSMs and delimiters there are no resources to free. // For VSMs and delimiters there are no resources to free.
if (msg_->content == (zmq::msg_content_t*) ZMQ_DELIMITER || if (msg_->content != (zmq::msg_content_t*) ZMQ_DELIMITER &&
msg_->content == (zmq::msg_content_t*) ZMQ_VSM) msg_->content != (zmq::msg_content_t*) ZMQ_VSM) {
return 0;
// If the content is not shared, or if it is shared and the reference. // If the content is not shared, or if it is shared and the reference.
// count has dropped to zero, deallocate it. // count has dropped to zero, deallocate it.
...@@ -171,6 +170,13 @@ int zmq_msg_close (zmq_msg_t *msg_) ...@@ -171,6 +170,13 @@ int zmq_msg_close (zmq_msg_t *msg_)
content->ffn (content->data, content->hint); content->ffn (content->data, content->hint);
free (content); free (content);
} }
}
// As a safety measure, let's make the deallocated message look like
// an empty message.
msg_->content = (zmq::msg_content_t*) ZMQ_VSM;
msg_->flags = 0;
msg_->vsm_size = 0;
return 0; return 0;
} }
......
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