]> git.ipfire.org Git - thirdparty/git.git/commit
diffcore-order: fix leaking buffer when parsing orderfiles
authorPatrick Steinhardt <ps@pks.im>
Thu, 26 Sep 2024 11:46:37 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Sep 2024 15:25:35 +0000 (08:25 -0700)
commit6932ec81834003855486547cdc561cbbdd335389
tree1a53b2c55c38c097a869ccc49db6be974de436ea
parentcf8c4237ebc653fdbc3285a38945f407d08245e5
diffcore-order: fix leaking buffer when parsing orderfiles

In `prepare_order()` we parse an orderfile and assign it to a global
array. In order to save on some allocations, we replace newlines with
NUL characters and then assign pointers into the allocated buffer to
that array. This can cause the buffer to be completely unreferenced
though in some cases, e.g. because the order file is empty or because we
had to use `xmemdupz()` to copy the lines instead of NUL-terminating
them.

Refactor the code to always `xmemdupz()` the strings. This is a bit
simpler, and it is rather unlikely that saving a handful of allocations
really matters. This allows us to release the string buffer and thus
plug the memory leak.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diffcore-order.c
t/t4056-diff-order.sh
t/t4204-patch-id.sh