From 15bcc4a1f0ff5a48295143b1e3c556f8c60f3bfd Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 5 Aug 2016 16:50:58 +1000 Subject: [PATCH] ctdb-daemon: Fix CID 1125627 Resource leak (RESOURCE_LEAK) Also fixes CID 1125628. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12110 Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs (cherry picked from commit 940272d215049f5f5079aa926e69eae1985a4bfa) --- ctdb/server/ctdb_logging.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c index 129bdc9e7f6..a72d8bf8443 100644 --- a/ctdb/server/ctdb_logging.c +++ b/ctdb/server/ctdb_logging.c @@ -269,9 +269,14 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb) /* We'll fail if stderr/stdout not already open; it's simpler. */ old_stdout = dup(STDOUT_FILENO); + if (old_stdout < 0) { + DEBUG(DEBUG_ERR, ("Failed to dup stdout for child logging\n")); + return -1; + } old_stderr = dup(STDERR_FILENO); - if (old_stdout < 0 || old_stderr < 0) { - DEBUG(DEBUG_ERR, ("Failed to dup stdout/stderr for child logging\n")); + if (old_stderr < 0) { + DEBUG(DEBUG_ERR, ("Failed to dup stderr for child logging\n")); + close(old_stdout); return -1; } if (dup2(p[1], STDOUT_FILENO) < 0 || dup2(p[1], STDERR_FILENO) < 0) { -- 2.47.2