]> git.ipfire.org Git - thirdparty/git.git/commit
strbuf: fix leak when `appendwholeline()` fails with EOF
authorPatrick Steinhardt <ps@pks.im>
Mon, 27 May 2024 11:46:01 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 18:19:58 +0000 (11:19 -0700)
commit94e2aa555e7dab4f5296a8dcd8605d751e02b12d
tree65c7385b4f3ac594ce09fb2859510a22313c60f2
parent97613b9cb91eb97b8a4df547396465f3184ccdef
strbuf: fix leak when `appendwholeline()` fails with EOF

In `strbuf_appendwholeline()` we call `strbuf_getwholeline()` with a
temporary buffer. In case the call returns an error we indicate this by
returning EOF, but never release the temporary buffer. This can cause a
leak though because `strbuf_getwholeline()` calls getline(3). Quoting
its documentation:

    If *lineptr was set to NULL before the call, then the buffer
    should be freed by the user program even on failure.

Consequently, the temporary buffer may hold allocated memory even when
the call to `strbuf_getwholeline()` fails.

Fix this by releasing the temporary buffer on error.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
strbuf.c
t/t1400-update-ref.sh