mirror of
https://github.com/git/git.git
synced 2024-06-07 21:16:10 +02:00
strbuf doc: reuse after strbuf_release is fine
strbuf_release leaves the strbuf in a valid, initialized state, so there is no 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). Document the semantics so the next generation of Git developers can become familiar with them without reading the implementation. It is still not advisable to call strbuf_release too often because it is wasteful, so add a note pointing to strbuf_reset for that. The same semantics apply to strbuf_detach. Add a similar note to its docstring to make that clear. Improved-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
4010f1d1b7
commit
e0222159fa
11
strbuf.h
11
strbuf.h
|
@ -82,8 +82,12 @@ extern char strbuf_slopbuf[];
|
||||||
extern void strbuf_init(struct strbuf *, size_t);
|
extern void strbuf_init(struct strbuf *, size_t);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release a string buffer and the memory it used. You should not use the
|
* Release a string buffer and the memory it used. After this call, the
|
||||||
* string buffer after using this function, unless you initialize it again.
|
* strbuf points to an empty string that does not need to be free()ed, as
|
||||||
|
* if it had been set to `STRBUF_INIT` and never modified.
|
||||||
|
*
|
||||||
|
* To clear a strbuf in preparation for further use without the overhead
|
||||||
|
* of free()ing and malloc()ing again, use strbuf_reset() instead.
|
||||||
*/
|
*/
|
||||||
extern void strbuf_release(struct strbuf *);
|
extern void strbuf_release(struct strbuf *);
|
||||||
|
|
||||||
|
@ -91,6 +95,9 @@ extern void strbuf_release(struct strbuf *);
|
||||||
* Detach the string from the strbuf and returns it; you now own the
|
* Detach the string from the strbuf and returns it; you now own the
|
||||||
* storage the string occupies and it is your responsibility from then on
|
* storage the string occupies and it is your responsibility from then on
|
||||||
* to release it with `free(3)` when you are done with it.
|
* to release it with `free(3)` when you are done with it.
|
||||||
|
*
|
||||||
|
* The strbuf that previously held the string is reset to `STRBUF_INIT` so
|
||||||
|
* it can be reused after calling this function.
|
||||||
*/
|
*/
|
||||||
extern char *strbuf_detach(struct strbuf *, size_t *);
|
extern char *strbuf_detach(struct strbuf *, size_t *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue