Commit 94fb63ee authored by Frederic Logier's avatar Frederic Logier
Browse files

use local z_message to remove a memory leak on stream data

parent 85acfd50
......@@ -1556,11 +1556,12 @@ void Zstream_push::stream_payload()
BSONObj b_filename = BSON("filename" << filename);
zmq::message_t z_message;
zmq::message_t z_message(2);
z_message.rebuild(b_filename.objsize());
memcpy ((void *) z_message.data(), (char*)b_filename.objdata(), b_filename.objsize());
z_stream->send (&z_message, ZMQ_NOBLOCK);
//z_stream->send (&z_message, ZMQ_NOBLOCK);
z_stream->send (z_message);
goto flush_socket;
}
......@@ -1643,7 +1644,7 @@ void Zstream_push::stream_payload()
//std::cout << "Zstream_push::stream_payload CHUNK toBase64 LEN : " << chunk_length << " size : " << s_chunk_data.size() << std::endl;
zmq::message_t z_message;
zmq::message_t z_message(2);
z_message.rebuild(chunk_data.size());
memcpy((void *) z_message.data(), chunk_data.constData(), chunk_data.size());
......@@ -1652,7 +1653,9 @@ void Zstream_push::stream_payload()
bool l_res = z_stream->send(&z_message, (chunk_index+1<num_chunck)? ZMQ_SNDMORE | ZMQ_NOBLOCK: 0);
// bool l_res = z_stream->send(&z_message, (chunk_index+1<num_chunck)? ZMQ_SNDMORE | ZMQ_NOBLOCK: 0);
bool l_res = z_stream->send(z_message, (chunk_index+1<num_chunck)? ZMQ_SNDMORE : 0);
if (!l_res)
{
std::cout << "ERROR ON STREAMING DATA" << std::endl;
......@@ -1669,11 +1672,11 @@ void Zstream_push::stream_payload()
{
gfsid = BSON("error" << "filename not found : " + t_payload.getField("filename").str());
zmq::message_t z_message;
zmq::message_t z_message(2);
z_message.rebuild(gfsid.objsize());
memcpy((void *) z_message.data(), gfsid.objdata(), gfsid.objsize());
bool l_res = z_stream->send(&z_message, 0);
bool l_res = z_stream->send(z_message, 0);
if (!l_res)
{
std::cout << "ERROR ON ERROR DATA" << std::endl;
......@@ -1688,10 +1691,11 @@ void Zstream_push::stream_payload()
else
{
BSONObj b_error = BSON("error" << "action unknown : " + payload_action.toStdString());
zmq::message_t z_message;
zmq::message_t z_message(2);
z_message.rebuild(b_error.objsize());
memcpy ((void *) z_message.data(), (char*)b_error.objdata(), b_error.objsize());
z_stream->send (&z_message, ZMQ_NOBLOCK);
//z_stream->send (&z_message, ZMQ_NOBLOCK);
z_stream->send (z_message);
goto flush_socket;
}
}
......
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