From: Rys Sommefeldt <rys@pixeltards.com>
To: git@vger.kernel.org
Subject: [cgit PATCH] Close file descriptor on error in readfile()
Date: Sat, 07 Nov 2009 02:01:16 +0000 [thread overview]
Message-ID: <4AF4D4EC.1040806@pixeltards.com> (raw)
Hi Lars,
My colleagues and I use cgit at work, and we've found that the scanning
process can consume all available fds pretty quickly on our cgit hosts,
because it doesn't close them properly on error. We have a few thousand
active repositories for cgit to scan, and we noticed it dying after a
certain amount.
I've attached a patch which should apply against current master,
although I developed it a while back on an older 0.8 version (sorry it
took so long to subscribe and send the patch in).
Cheers,
Rys Sommefeldt
---
From 6446cf839d2104cd40848e439bf97cd7fd6ccfee Mon Sep 17 00:00:00 2001
From: Rys Sommefeldt <rsommefeldt@plus.net>
Date: Fri, 6 Nov 2009 17:14:56 +0000
Subject: [PATCH] Close fd when done
---
shared.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/shared.c b/shared.c
index d7b2d5a..d5e54e6 100644
--- a/shared.c
+++ b/shared.c
@@ -404,14 +404,19 @@ int readfile(const char *path, char **buf, size_t
*size)
struct stat st;
fd = open(path, O_RDONLY);
- if (fd == -1)
+ if (fd == -1) {
+ close(fd);
return errno;
- if (fstat(fd, &st))
+ }
+ if (fstat(fd, &st)) {
+ close(fd);
return errno;
+ }
if (!S_ISREG(st.st_mode))
return EISDIR;
*buf = xmalloc(st.st_size + 1);
*size = read_in_full(fd, *buf, st.st_size);
(*buf)[*size] = '\0';
+ close(fd);
return (*size == st.st_size ? 0 : errno);
}
--
1.6.5.2
next reply other threads:[~2009-11-07 2:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-07 2:01 Rys Sommefeldt [this message]
2009-11-07 2:22 ` [cgit PATCH] Close file descriptor on error in readfile() Steven Noonan
2009-11-07 2:26 ` Rys Sommefeldt
2009-11-07 12:23 ` Rys Sommefeldt
2009-11-07 14:59 ` Lars Hjemli
2009-11-07 16:14 ` Andreas Schwab
2009-11-07 17:15 ` Lars Hjemli
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 \
--in-reply-to=4AF4D4EC.1040806@pixeltards.com \
--to=rys@pixeltards.com \
--cc=git@vger.kernel.org \
/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