You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/07/19 01:17:19 UTC

mesos git commit: Fixed a memory lifetime issue in LibeventSSLSocketImp::send.

Repository: mesos
Updated Branches:
  refs/heads/master 6c628d4a3 -> 4d97171c1


Fixed a memory lifetime issue in LibeventSSLSocketImp::send.

This function accidentally assumed that 'data' will live beyond the
scope of the call, by using 'data' within an asynchronous context.

This copies the data into an 'evbuffer' which will then get moved
into the output buffer in the event loop. Note that this does not
introduce an additional copy: we still have a single copy to get
'data' into the bufferevent output buffer.

Review: https://reviews.apache.org/r/50163


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/4d97171c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/4d97171c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/4d97171c

Branch: refs/heads/master
Commit: 4d97171c16c2d13fa876031d7b796d8b514f18fc
Parents: 6c628d4
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Jul 18 14:32:52 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Jul 18 18:16:46 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/libevent_ssl_socket.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4d97171c/3rdparty/libprocess/src/libevent_ssl_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent_ssl_socket.cpp b/3rdparty/libprocess/src/libevent_ssl_socket.cpp
index 2e7f332..f4c0b0b 100644
--- a/3rdparty/libprocess/src/libevent_ssl_socket.cpp
+++ b/3rdparty/libprocess/src/libevent_ssl_socket.cpp
@@ -711,6 +711,11 @@ Future<size_t> LibeventSSLSocketImpl::send(const char* data, size_t size)
     std::swap(request, send_request);
   }
 
+  evbuffer* buffer = CHECK_NOTNULL(evbuffer_new());
+
+  int result = evbuffer_add(buffer, data, size);
+  CHECK_EQ(0, result);
+
   // Extend the life-time of 'this' through the execution of the
   // lambda in the event loop. Note: The 'self' needs to be explicitly
   // captured because we're not using it in the body of the lambda. We
@@ -719,7 +724,7 @@ Future<size_t> LibeventSSLSocketImpl::send(const char* data, size_t size)
   auto self = shared(this);
 
   run_in_event_loop(
-      [self, data, size]() {
+      [self, buffer]() {
         CHECK(__in_event_loop__);
         CHECK(self);
 
@@ -730,7 +735,10 @@ Future<size_t> LibeventSSLSocketImpl::send(const char* data, size_t size)
           CHECK_NOTNULL(self->send_request.get());
         }
 
-        bufferevent_write(self->bev, data, size);
+        int result = bufferevent_write_buffer(self->bev, buffer);
+        CHECK_EQ(0, result);
+
+        evbuffer_free(buffer);
       },
       DISALLOW_SHORT_CIRCUIT);