]> Kevux Git Server - rit/commit
worktree: do not pass strbuf by value
authorDeveshi Dwivedi <deveshigurgaon@gmail.com>
Wed, 11 Mar 2026 17:33:35 +0000 (17:33 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Mar 2026 18:08:53 +0000 (11:08 -0700)
commit4107c0bb3455905aeacdba3be09b20e62b310eaa
treed7ff086e3ee3d044029dc61aadc25014c4ce3ba9
parent795c338de725e13bd361214c6b768019fc45a2c1
worktree: do not pass strbuf by value

write_worktree_linking_files() takes two struct strbuf parameters by
value, even though it only reads path strings from them.

Passing a strbuf by value is misleading and dangerous. The structure
carries a pointer to its underlying character array; caller and callee
end up sharing that storage.  If the callee ever causes the strbuf to
be reallocated, the caller's copy becomes a dangling pointer, which
results in a double-free when the caller does strbuf_release().

The function only needs the string values, not the strbuf machinery.
Switch it to take const char * and update all callers to pass .buf.

Signed-off-by: Deveshi Dwivedi <deveshigurgaon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c
worktree.c
worktree.h