From fdf162a117782720ed8b7a1cbb71194f0c5136a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lourens=20Naud=C3=A9?= Date: Fri, 16 Nov 2012 17:21:07 +0000 Subject: [PATCH] [LIBZMQ-450] Copy the stream engine endpoint - string reference caused memory corruption --- src/stream_engine.cpp | 6 ++++-- src/stream_engine.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 57381d5e59..0c7f38fcad 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -63,7 +63,6 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_, const options_t &options_, cons greeting_bytes_read (0), session (NULL), options (options_), - endpoint (endpoint_), plugged (false), socket (NULL) { @@ -96,6 +95,8 @@ zmq::stream_engine_t::stream_engine_t (fd_t fd_, const options_t &options_, cons int rc = setsockopt (s, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof (int)); errno_assert (rc == 0); #endif + endpoint = new char[endpoint_.length() + 1]; + strcpy (endpoint, endpoint_.c_str()); } zmq::stream_engine_t::~stream_engine_t () @@ -117,6 +118,7 @@ zmq::stream_engine_t::~stream_engine_t () delete encoder; if (decoder != NULL) delete decoder; + delete [] endpoint; } void zmq::stream_engine_t::plug (io_thread_t *io_thread_, @@ -484,7 +486,7 @@ int zmq::stream_engine_t::push_msg (msg_t *msg_) void zmq::stream_engine_t::error () { zmq_assert (session); - socket->event_disconnected (endpoint.c_str(), s); + socket->event_disconnected (endpoint, s); session->detach (); unplug (); delete this; diff --git a/src/stream_engine.hpp b/src/stream_engine.hpp index 2d83995ce1..4a846c713e 100644 --- a/src/stream_engine.hpp +++ b/src/stream_engine.hpp @@ -132,7 +132,7 @@ namespace zmq options_t options; // String representation of endpoint - std::string endpoint; + char *endpoint; bool plugged;