From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from integral2.. (unknown [125.160.108.65]) by gnuweeb.org (Postfix) with ESMTPSA id 41FA57F921; Sun, 26 Jun 2022 02:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1656211549; bh=oabbAgf0rbXhNFJzX8uOSvXi0aZTx0BboRVtRbDFq8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlxuKeZ3J6HAenkT2H45fGPtX6uOyHgc+/GtcVaRa3NYGxxCUrvn2XNqemihvbhHH WTgqt/+ptR8Y8iXsS8HDS74TlOlfixnt2BigpHQamt5ypaEQdbmWVug8KxXQ9qt8gC wdLyQLNSvFT++LgFHFTtZemfBsBjcU/2SenzK5JWyfYuYamJKynufiXxscP0Q/Qs/+ tqCy93Ox97Gq3pBQSZpd5PszIjww0v31VCSMdV8KU/c41YA+CjOmN6P/F3C5GXgi6X x0ZW6Ajvj4rfZdwWQuBEyyWgnkL1b4JtVvRZWuXKzXmNPNCPdwg4IQ4Woy8RM9qk2U nX3fAX6f4XTdg== From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Ammar Faizi , Yonle Subject: [PATCH gwhttpd 2/2] gwhttpd: Fix `EBADF` errors at destruction Date: Sun, 26 Jun 2022 09:45:31 +0700 Message-Id: <20220626024531.657451-3-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220626024531.657451-1-ammarfaizi2@gnuweeb.org> References: <20220626024531.657451-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: When Yonle reported an issue about error on bind(), he attached an strace output and it has many EBADF errors like this: close(0) = 0 close(0) = -1 EBADF (Bad file descriptor) close(0) = -1 EBADF (Bad file descriptor) close(0) = -1 EBADF (Bad file descriptor) close(0) = -1 EBADF (Bad file descriptor) close(0) = -1 EBADF (Bad file descriptor) ... This happens because all sess[i].fd is set to 0 at initialization while the destructor is supposed to close the file descriptor when it's not equal to -1. Fix this by setting all file descriptor fields to -1 at initialization. Link: https://github.com/ammarfaizi2/gwhttpd/issues/1 Reported-by: Yonle Signed-off-by: Ammar Faizi --- gwhttpd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gwhttpd.cpp b/gwhttpd.cpp index d038939..0f4261d 100644 --- a/gwhttpd.cpp +++ b/gwhttpd.cpp @@ -111,6 +111,7 @@ static int init_state(struct server_state *state) } for (i = NR_MAX_CLIENTS - 1; i--; ) { + state->sess[i].fd = -1; state->sess[i].idx = i; state->sess_free_idx->push(i); } -- Ammar Faizi