git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Jonathan Tan <jonathantanmy@google.com>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH] sha1_loose_object_info: handle errors from unpack_sha1_rest
Date: Tue, 10 Oct 2017 10:34:01 +0900	[thread overview]
Message-ID: <xmqq376rrdkm.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20171006043847.hja2yjlvatckgy4d@sigill.intra.peff.net> (Jeff King's message of "Fri, 6 Oct 2017 00:38:47 -0400")

Jeff King <peff@peff.net> writes:

> Actually, there are only two callers left these days. One of them leaks,
> and the other immediately closes the zstream. So something like:
>
> diff --git a/sha1_file.c b/sha1_file.c
> index 09ad64ce55..cea003d182 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -978,10 +978,10 @@ static void *unpack_sha1_rest(git_zstream *stream, void *buffer, unsigned long s
>  		while (status == Z_OK)
>  			status = git_inflate(stream, Z_FINISH);
>  	}
> -	if (status == Z_STREAM_END && !stream->avail_in) {
> -		git_inflate_end(stream);
> +	git_inflate_end(stream);
> +
> +	if (status == Z_STREAM_END && !stream->avail_in)
>  		return buf;
> -	}
>  
>  	if (status < 0)
>  		error("corrupt loose object '%s'", sha1_to_hex(sha1));
> @@ -2107,7 +2107,6 @@ int read_loose_object(const char *path,
>  		*contents = unpack_sha1_rest(&stream, hdr, *size, expected_sha1);
>  		if (!*contents) {
>  			error("unable to unpack contents of %s", path);
> -			git_inflate_end(&stream);
>  			goto out;
>  		}
>  		if (check_sha1_signature(expected_sha1, *contents,
>
> seems reasonable. Doing it that (with my other patch on top) splits the
> leak-fix and the not-yet-a-bug-but-confusing-error-return problems into
> two separate patches.
>
> I dunno. There aren't that many callers of unpack_sha1_rest(), so it may
> not matter that much, but while we're here...

Yeah, I agree that it is a reasonable thing to do.

      reply	other threads:[~2017-10-10  1:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05  5:59 [PATCH] sha1_loose_object_info: handle errors from unpack_sha1_rest Jeff King
2017-10-06  4:19 ` Junio C Hamano
2017-10-06  4:30   ` Jeff King
2017-10-06  4:38     ` Jeff King
2017-10-10  1:34       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqq376rrdkm.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).