Re: [PATCH v2 1/4] streaming: allow to call close_istream(NULL);
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 18, 2012, 21:02 UTC
- Message-ID
- <xmqqobpl2oep.fsf@junio.mtv.corp.google.com>
- In-Reply-To
- <1337169731-23416-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> This makes it more convenient in cleanup code, like free(NULL).
If the justification were "like fclose(NULL)", it have made more sense, but fclose(NULL) does not silently turn itself into a successful no-op. You are expected to check the returned value from the matching function (i.e. fopen()) and do not call it. So taking this patch alone, I smell a bad design taste.
Show 18 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> streaming.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/streaming.c b/streaming.c
> index 3a3cd12..38b39cd 100644
> --- a/streaming.c
> +++ b/streaming.c
> @@ -94,7 +94,7 @@ struct git_istream {
>
> int close_istream(struct git_istream *st)
> {
> - int r = st->vtbl->close(st);
> + int r = st ? st->vtbl->close(st) : 0;
> free(st);
> return r;
> }