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 2015/09/29 23:28:45 UTC
mesos git commit: Fixed fd leaks in Socket::create and replace
sentinel with Option.
Repository: mesos
Updated Branches:
refs/heads/master 15613c806 -> a6f1cf3a5
Fixed fd leaks in Socket::create and replace sentinel with Option.
Review: https://reviews.apache.org/r/38809
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a6f1cf3a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a6f1cf3a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a6f1cf3a
Branch: refs/heads/master
Commit: a6f1cf3a59e4a6e0bdff5cd19644cd2bc2653425
Parents: 15613c8
Author: Chi Zhang <ch...@gmail.com>
Authored: Tue Sep 29 14:27:31 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Tue Sep 29 14:28:07 2015 -0700
----------------------------------------------------------------------
3rdparty/libprocess/include/process/socket.hpp | 2 +-
3rdparty/libprocess/src/socket.cpp | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a6f1cf3a/3rdparty/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp
index 817cb37..4b2597f 100644
--- a/3rdparty/libprocess/include/process/socket.hpp
+++ b/3rdparty/libprocess/include/process/socket.hpp
@@ -61,7 +61,7 @@ public:
*
* @return An instance of a `Socket`.
*/
- static Try<Socket> create(Kind kind = DEFAULT_KIND(), int s = -1);
+ static Try<Socket> create(Kind kind = DEFAULT_KIND(), Option<int> s = None());
/**
* Returns the default `Kind` of implementation of `Socket`.
http://git-wip-us.apache.org/repos/asf/mesos/blob/a6f1cf3a/3rdparty/libprocess/src/socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/socket.cpp b/3rdparty/libprocess/src/socket.cpp
index 5879423..6ac834e 100644
--- a/3rdparty/libprocess/src/socket.cpp
+++ b/3rdparty/libprocess/src/socket.cpp
@@ -34,9 +34,13 @@ using std::string;
namespace process {
namespace network {
-Try<Socket> Socket::create(Kind kind, int s)
+Try<Socket> Socket::create(Kind kind, Option<int> s)
{
- if (s < 0) {
+ // If the caller passed in a file descriptor, we do
+ // not own its life cycle and must not close it.
+ bool owned = s.isNone();
+
+ if (owned) {
// Supported in Linux >= 2.6.27.
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
Try<int> fd =
@@ -53,11 +57,13 @@ Try<Socket> Socket::create(Kind kind, int s)
Try<Nothing> nonblock = os::nonblock(fd.get());
if (nonblock.isError()) {
+ os::close(fd.get());
return Error("Failed to create socket, nonblock: " + nonblock.error());
}
Try<Nothing> cloexec = os::cloexec(fd.get());
if (cloexec.isError()) {
+ os::close(fd.get());
return Error("Failed to create socket, cloexec: " + cloexec.error());
}
#endif
@@ -67,8 +73,12 @@ Try<Socket> Socket::create(Kind kind, int s)
switch (kind) {
case POLL: {
- Try<std::shared_ptr<Socket::Impl>> socket = PollSocketImpl::create(s);
+ Try<std::shared_ptr<Socket::Impl>> socket =
+ PollSocketImpl::create(s.get());
if (socket.isError()) {
+ if (owned) {
+ os::close(s.get());
+ }
return Error(socket.error());
}
return Socket(socket.get());
@@ -76,8 +86,11 @@ Try<Socket> Socket::create(Kind kind, int s)
#ifdef USE_SSL_SOCKET
case SSL: {
Try<std::shared_ptr<Socket::Impl>> socket =
- LibeventSSLSocketImpl::create(s);
+ LibeventSSLSocketImpl::create(s.get());
if (socket.isError()) {
+ if (owned) {
+ os::close(s.get());
+ }
return Error(socket.error());
}
return Socket(socket.get());