From 71a93cf0f0db755dd6e9f8688f2ef460c68c756d Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 1 Jul 2018 12:58:05 +0300 Subject: [PATCH] lib: i_close_fd_path() - Replace assert with more descriptive panic Since this function can be called from so many places, it's easier to figure out the bug if the panic message contains what called it. --- src/lib/fd-util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/fd-util.c b/src/lib/fd-util.c index a57419fc62..45dcfcf2d9 100644 --- a/src/lib/fd-util.c +++ b/src/lib/fd-util.c @@ -140,7 +140,13 @@ void i_close_fd_path(int *fd, const char *path, const char *arg, if (*fd == -1) return; - i_assert(*fd > 0); + if (unlikely(*fd <= 0)) { + i_panic("%s: close(%s%s%s) @ %s:%d attempted with fd=%d", + func, arg, + (path == NULL) ? "" : " = ", + (path == NULL) ? "" : path, + file, line, *fd); + } saved_errno = errno; if (unlikely(close(*fd) < 0)) -- 2.47.3