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 02:30:12 UTC

mesos git commit: Fixed a file descriptor leak in slave/state.cpp.

Repository: mesos
Updated Branches:
  refs/heads/master 45e40348c -> 9a675a121


Fixed a file descriptor leak in slave/state.cpp.

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


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

Branch: refs/heads/master
Commit: 9a675a12152b3424f011a234a34069c4e53df889
Parents: 45e4034
Author: Chi Zhang <ch...@gmail.com>
Authored: Mon Sep 28 17:28:56 2015 -0700
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Mon Sep 28 17:29:58 2015 -0700

----------------------------------------------------------------------
 src/slave/state.cpp | 37 ++++++++++---------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9a675a12/src/slave/state.cpp
----------------------------------------------------------------------
diff --git a/src/slave/state.cpp b/src/slave/state.cpp
index 47c66dc..81c4b96 100644
--- a/src/slave/state.cpp
+++ b/src/slave/state.cpp
@@ -632,6 +632,7 @@ Try<TaskState> TaskState::recover(
   off_t offset = lseek(fd.get(), 0, SEEK_CUR);
 
   if (offset < 0) {
+    os::close(fd.get());
     return ErrnoError("Failed to lseek status updates file '" + path + "'");
   }
 
@@ -640,6 +641,7 @@ Try<TaskState> TaskState::recover(
   // errors above, because the 'fd' is properly set to the end of the
   // last valid update by 'protobuf::read()'.
   if (ftruncate(fd.get(), offset) != 0) {
+    os::close(fd.get());
     return ErrnoError(
         "Failed to truncate status updates file '" + path + "'");
   }
@@ -650,6 +652,8 @@ Try<TaskState> TaskState::recover(
     message = "Failed to read status updates file  '" + path +
               "': " + record.error();
 
+    os::close(fd.get());
+
     if (strict) {
       return Error(message);
     } else {
@@ -660,20 +664,7 @@ Try<TaskState> TaskState::recover(
   }
 
   // Close the updates file.
-  Try<Nothing> close = os::close(fd.get());
-
-  if (close.isError()) {
-    message = "Failed to close status updates file '" + path +
-              "': " + close.error();
-
-    if (strict) {
-      return Error(message);
-    } else {
-      LOG(WARNING) << message;
-      state.errors++;
-      return state;
-    }
-  }
+  os::close(fd.get());
 
   return state;
 }
@@ -719,6 +710,7 @@ Try<ResourcesState> ResourcesState::recover(
 
   off_t offset = lseek(fd.get(), 0, SEEK_CUR);
   if (offset < 0) {
+    os::close(fd.get());
     return ErrnoError("Failed to lseek resources file '" + path + "'");
   }
 
@@ -727,6 +719,7 @@ Try<ResourcesState> ResourcesState::recover(
   // errors above, because the 'fd' is properly set to the end of the
   // last valid resource by 'protobuf::read()'.
   if (ftruncate(fd.get(), offset) != 0) {
+    os::close(fd.get());
     return ErrnoError("Failed to truncate resources file '" + path + "'");
   }
 
@@ -736,19 +729,7 @@ Try<ResourcesState> ResourcesState::recover(
     string message =
       "Failed to read resources file  '" + path + "': " + resource.error();
 
-    if (strict) {
-      return Error(message);
-    } else {
-      LOG(WARNING) << message;
-      state.errors++;
-      return state;
-    }
-  }
-
-  Try<Nothing> close = os::close(fd.get());
-  if (close.isError()) {
-    string message =
-      "Failed to close resources file '" + path + "': " + close.error();
+    os::close(fd.get());
 
     if (strict) {
       return Error(message);
@@ -759,6 +740,8 @@ Try<ResourcesState> ResourcesState::recover(
     }
   }
 
+  os::close(fd.get());
+
   return state;
 }