Skip to content

Commit

Permalink
[LIBZMQ-450] Copy the stream engine endpoint - string reference cause…
Browse files Browse the repository at this point in the history
…d memory corruption
  • Loading branch information
methodmissing committed Nov 16, 2012
1 parent bef9a41 commit fdf162a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/stream_engine.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ()
Expand All @@ -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_,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/stream_engine.hpp
Expand Up @@ -132,7 +132,7 @@ namespace zmq
options_t options;

// String representation of endpoint
std::string endpoint;
char *endpoint;

bool plugged;

Expand Down

0 comments on commit fdf162a

Please sign in to comment.