]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: i_close_fd(-1) should be a no-op
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Tue, 6 Jun 2017 07:13:15 +0000 (10:13 +0300)
committerJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Wed, 20 Sep 2017 09:29:06 +0000 (12:29 +0300)
src/lib/macros.h

index 4cbab19320811d13a9c8a817018f491ef896c065..2bb96300db4e3ecf98d33335320993f9ba0eee92 100644 (file)
 
 #endif
 
-/* Close the fd and set it to -1. This assert-crashes if fd == 0. Normally
-   this would happen only if an uninitialized fd is attempted to be closed,
-   which is a bug. */
+/* Close the fd and set it to -1. This assert-crashes if fd == 0, and is a
+   no-op if fd == -1. Normally fd == 0 would happen only if an uninitialized
+   fd is attempted to be closed, which is a bug. */
 #define i_close_fd(fd) STMT_START {  \
-       i_assert(*fd > 0); \
-       if (unlikely(close_keep_errno(fd) < 0)) \
-               i_error("close(%d[%s:%d]) failed: %m", \
-                       *(fd), __FILE__, __LINE__); \
+       if (*fd != -1) { \
+               i_assert(*fd > 0); \
+               if (unlikely(close_keep_errno(fd) < 0)) \
+                       i_error("close(%d[%s:%d]) failed: %m", \
+                               *(fd), __FILE__, __LINE__); \
+       } \
        } STMT_END
 
 #define i_unreached() \