Re: [PATCH] branch: reset instead of release a strbuf
- Date: Tue, 3 Oct 2017 15:24:14 -0700
- From: Jonathan Nieder <jrnieder@xxxxxxxxx>
- Subject: Re: [PATCH] branch: reset instead of release a strbuf
Stefan Beller wrote:
> Our documentation advises to not re-use a strbuf, after strbuf_release
> has been called on it. Use the proper reset instead.
> Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
This is indeed
Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
> Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
> builtin/branch.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
Here's a patch to address the surprising strbuf.h advice.
-- >8 --
Subject: strbuf: do not encourage init-after-release
strbuf_release already leaves the strbuf in a valid, initialized
state, so there is not need to call strbuf_init after it.
Moreover, this is not likely to change in the future: strbuf_release
leaving the strbuf in a valid state has been easy to maintain and has
been very helpful for Git's robustness and simplicity (e.g.,
preventing use-after-free vulnerabilities).
It is still not advisable to call strbuf_release until done using a
strbuf because it is wasteful, so keep that part of the advice.
Reported-by: Stefan Beller <sbeller@xxxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
strbuf.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.h b/strbuf.h
index 7496cb8ec5..6e175c3694 100644
@@ -83,7 +83,7 @@ extern void strbuf_init(struct strbuf *, size_t);
* Release a string buffer and the memory it used. You should not use the
- * string buffer after using this function, unless you initialize it again.
+ * string buffer after using this function.
extern void strbuf_release(struct strbuf *);