From: Junio C Hamano <gitster@pobox.com>
To: Guanqun Lu <guanqun.lu@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] lockfile: set lk->fd = -1 in 'rollback_lock_file()'
Date: Tue, 10 Feb 2009 07:29:59 -0800 [thread overview]
Message-ID: <7v63jipax4.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1234334612-24907-2-git-send-email-guanqun.lu@gmail.com> (Guanqun Lu's message of "Wed, 11 Feb 2009 14:43:32 +0800")
Guanqun Lu <guanqun.lu@gmail.com> writes:
> Post-conditions when these functions return successfully:
> lk->fd == -1? lk->filename[0] == '\0'?
> close_lock_file() yes no
> commit_lock_file() yes yes
> rollback_lock_file() no* yes
>
> [*] This commit changes this 'no' in rollback_lock_file() to 'yes',
> which achieves more robust and unified interface.
Is there a broken caller this patch fixes? IOW, is there a codepath that
can call rollback and then later notices lk->fd is not negative and uses
it without checking lk->filename[0] first?
> Signed-off-by: Guanqun Lu <guanqun.lu@gmail.com>
> ---
> lockfile.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/lockfile.c b/lockfile.c
> index 021c337..44e5253 100644
> --- a/lockfile.c
> +++ b/lockfile.c
> @@ -243,8 +243,10 @@ int commit_locked_index(struct lock_file *lk)
> void rollback_lock_file(struct lock_file *lk)
> {
> if (lk->filename[0]) {
> - if (lk->fd >= 0)
> + if (lk->fd >= 0) {
> close(lk->fd);
> + lk->fd = -1;
> + }
> unlink(lk->filename);
> }
> lk->filename[0] = 0;
> --
> 1.6.1.2.392.gb04d1
prev parent reply other threads:[~2009-02-10 15:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-11 6:43 [PATCH 1/2] code cleanup in sha1_file.c: xmalloc -> xcalloc Guanqun Lu
2009-02-10 16:29 ` Brandon Casey
2009-02-10 16:43 ` Junio C Hamano
2009-02-11 6:43 ` [PATCH 2/2] lockfile: set lk->fd = -1 in 'rollback_lock_file()' Guanqun Lu
2009-02-10 15:29 ` Junio C Hamano [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 \
--in-reply-to=7v63jipax4.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=guanqun.lu@gmail.com \
/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).