From 4107c0bb3455905aeacdba3be09b20e62b310eaa Mon Sep 17 00:00:00 2001 From: Deveshi Dwivedi Date: Wed, 11 Mar 2026 17:33:35 +0000 Subject: 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 Signed-off-by: Junio C Hamano --- worktree.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'worktree.h') diff --git a/worktree.h b/worktree.h index 06efe26b83..f4e46be385 100644 --- a/worktree.h +++ b/worktree.h @@ -240,7 +240,7 @@ int init_worktree_config(struct repository *r); * dotgit: "/path/to/foo/.git" * gitdir: "/path/to/repo/worktrees/foo/gitdir" */ -void write_worktree_linking_files(struct strbuf dotgit, struct strbuf gitdir, +void write_worktree_linking_files(const char *dotgit, const char *gitdir, int use_relative_paths); #endif -- cgit v1.3