public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: GNU/Weeb Mailing List <[email protected]>
Cc: Ammar Faizi <[email protected]>, Yonle <[email protected]>
Subject: [PATCH gwhttpd 2/2] gwhttpd: Fix `EBADF` errors at destruction
Date: Sun, 26 Jun 2022 09:45:31 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
Signed-off-by: Ammar Faizi <[email protected]>
---
 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


      parent reply	other threads:[~2022-06-26  2:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-26  2:45 [PATCH gwhttpd 0/2] Two gwhttpd fixes Ammar Faizi
2022-06-26  2:45 ` [PATCH gwhttpd 1/2] gwhttpd: Explicitly set sa_family before bind() Ammar Faizi
2022-06-26  2:45 ` Ammar Faizi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox