git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Junio C Hamano <junkio@cox.net>, Git Mailing List <git@vger.kernel.org>
Subject: Fix double "close()" in ce_compare_data
Date: Mon, 31 Jul 2006 09:55:15 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0607310945490.4168@g5.osdl.org> (raw)


Doing an "strace" on "git diff" shows that we close() a file descriptor 
twice (getting EBADFD on the second one) when we end up in ce_compare_data 
if the index does not match the checked-out stat information.

The "index_fd()" function will already have closed the fd for us, so we 
should not close it again.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

The way I found this also showed a potential performance problem: if you 
do a "git reset --hard" (or similar) after you have changes in your tree, 
it will write the index file with the same timestamp as the checked out 
files that it re-wrote.

That will also then forever afterwards (well, until the next "git 
update-index --refresh") cause the "uncommon" timestamp case in 
ce_match_stat(), where we check the index-file timestamp against the 
timestamp of the stat data, to trigger.

Not very good. The "ce_modified_check_fs()" tests can be quite expensive 
if you have lots of those files because we end up then calling the 
"ce_compare_data()" function a lot. And suddenly "git diff" doesn't take a 
tenth of a second any more.

We should really try to have some way to re-generate the index 
automatically when this case triggers, so that we only need to do it 
_once_ rather than keep doing it forever while the index is "potentially 
stale".

Any ideas?

diff --git a/read-cache.c b/read-cache.c
index c0b0313..f92cdaa 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -61,7 +61,7 @@ static int ce_compare_data(struct cache_
 		unsigned char sha1[20];
 		if (!index_fd(sha1, fd, st, 0, NULL))
 			match = memcmp(sha1, ce->sha1, 20);
-		close(fd);
+		/* index_fd() closed the file descriptor already */
 	}
 	return match;
 }

         reply	other threads:[~2006-07-31 16:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-15  9:00 [PATCH 0/6] Configuration tweaks for Solaris Dennis Stosberg
2006-08-15  9:01 ` [PATCH 1/6] Solaris has strlcpy() at least since version 8 Dennis Stosberg
2006-08-15  9:01 ` [PATCH 2/6] Solaris does not support C99 format strings before version 10 Dennis Stosberg
2006-08-15  9:01 ` [PATCH 3/6] Look for sockaddr_storage in sys/socket.h Dennis Stosberg
2006-08-15  9:01 ` [PATCH 4/6] Fix detection of ipv6 on Solaris Dennis Stosberg
2006-08-15  9:01 ` [PATCH 5/6] On Solaris nanosleep() is not in libc but in librt Dennis Stosberg
2006-08-15 10:35   ` Junio C Hamano
2006-07-31 16:55     ` Linus Torvalds [this message]
2006-07-31 19:05       ` Fix double "close()" in ce_compare_data Junio C Hamano
2006-08-05 11:20       ` [PATCH] Racy git: avoid having to be always too careful Junio C Hamano
2006-08-08 15:43         ` Johannes Schindelin
2006-08-08 17:25           ` Junio C Hamano
2006-08-08 22:30             ` Johannes Schindelin
2006-08-08 23:07               ` Junio C Hamano
2006-08-08 23:44                 ` Johannes Schindelin
2006-08-15 20:12       ` [PATCH] Documentation/technical/racy-git.txt Junio C Hamano
2006-08-15 11:18     ` [PATCH 5/6] On Solaris nanosleep() is not in libc but in librt Alex Riesen
2006-08-15  9:01 ` [PATCH 6/6] Fix compilation with Sun CC Dennis Stosberg

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=Pine.LNX.4.64.0607310945490.4168@g5.osdl.org \
    --to=torvalds@osdl.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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;
as well as URLs for NNTP newsgroup(s).