diff options
| author | Deveshi Dwivedi <deveshigurgaon@gmail.com> | 2026-03-11 17:33:35 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-11 11:08:53 -0700 |
| commit | 4107c0bb3455905aeacdba3be09b20e62b310eaa (patch) | |
| tree | d7ff086e3ee3d044029dc61aadc25014c4ce3ba9 /builtin | |
| parent | 795c338de725e13bd361214c6b768019fc45a2c1 (diff) | |
| download | git-4107c0bb3455905aeacdba3be09b20e62b310eaa.tar.xz | |
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>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/worktree.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index bc2d0d645b..4035b1cb06 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -539,7 +539,7 @@ static int add_worktree(const char *path, const char *refname, strbuf_reset(&sb); strbuf_addf(&sb, "%s/gitdir", sb_repo.buf); - write_worktree_linking_files(sb_git, sb, opts->relative_paths); + write_worktree_linking_files(sb_git.buf, sb.buf, opts->relative_paths); strbuf_reset(&sb); strbuf_addf(&sb, "%s/commondir", sb_repo.buf); write_file(sb.buf, "../.."); |
