]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3461] Addressed review comments.
authorMarcin Siodelski <marcin@isc.org>
Thu, 24 Jul 2014 12:25:51 +0000 (14:25 +0200)
committerMarcin Siodelski <marcin@isc.org>
Thu, 24 Jul 2014 12:25:51 +0000 (14:25 +0200)
src/lib/util/io/fd_share.cc

index bae9e2c0960910b7be94aaddd48544fc82b5af1c..5f69cd8ab0ee7dcaa18fc1b2d06ce25c80f94208 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010, 2014 Internet Systems Consortium, Inc. ("ISC")
 //
 // Permission to use, copy, modify, and/or distribute this software for any
 // purpose with or without fee is hereby granted, provided that the above
@@ -107,13 +107,15 @@ recv_fd(const int sock) {
         std::memcpy(&fd, CMSG_DATA(cmsg), sizeof(int));
     }
     free(msghdr.msg_control);
-    // It is strange, but the call can return the same file descriptor as
-    // one returned previously, even if that one is not closed yet. So,
-    // we just re-number every one we get, so they are unique.
-    int new_fd(dup(fd));
-    // Only call close() if the descriptor is valid. Otherwise return
-    // an error.
-    int close_error(fd >=0 ? close(fd) : -1);
+    int new_fd = -1;
+    int close_error = -1;
+    if (fd >= 0) {
+        // It is strange, but the call can return the same file descriptor as
+        // one returned previously, even if that one is not closed yet. So,
+        // we just re-number every one we get, so they are unique.
+        new_fd = dup(fd);
+        close_error = close(fd);
+    }
     if (close_error == -1 || new_fd == -1) {
         // We need to return an error, because something failed. But in case
         // it was the previous close, we at least try to close the duped FD.