From: Jeff King <peff@peff.net>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>,
Stefan Beller <sbeller@google.com>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] strbuf: release memory on read error in strbuf_read_once()
Date: Thu, 7 Dec 2017 16:28:55 -0500 [thread overview]
Message-ID: <20171207212855.GE12850@sigill.intra.peff.net> (raw)
In-Reply-To: <6a39662f-8ff2-c314-5348-4189737a6853@web.de>
On Thu, Dec 07, 2017 at 09:51:26PM +0100, René Scharfe wrote:
> If other strbuf add functions cause the first allocation and
> subsequently encounter an error then they release the memory, restoring
> the pristine state of the strbuf. That simplifies error handling for
> callers.
>
> Do the same in strbuf_read_once(), and do it also in case no bytes were
> read -- which may or may not be an error as well, depending on the
> caller.
Makes sense, and the patch is delightfully simple.
For the "0" case nobody should be negatively impacted by dropping the
allocation, as they get a sane 0-length string from the slopbuf (and
anybody who relies on sb->buf being allocated without calling detach or
similar is already doing it wrong).
-Peff
prev parent reply other threads:[~2017-12-07 21:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 20:51 [PATCH] strbuf: release memory on read error in strbuf_read_once() René Scharfe
2017-12-07 21:28 ` Jeff King [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=20171207212855.GE12850@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=sbeller@google.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.
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).