From: Junio C Hamano Date: Wed, 20 Apr 2016 17:05:06 GMT Subject: Re: [PATCH v2 03/12] worktree.c: make find_shared_symref() return struct worktree * Message-ID: In-Reply-To: <1461158693-21289-4-git-send-email-pclouds@gmail.com> Nguyễn Thái Ngọc Duy writes: > This gives the caller more information and they can answer things like, > "is it the main worktree" or "is it the current worktree". The latter > question is needed for the "checkout a rebase branch" case later. That makes good sense. > diff --git a/worktree.h b/worktree.h > index 3198c8d..d71d7ec 100644 > --- a/worktree.h > +++ b/worktree.h > @@ -36,9 +36,10 @@ extern void free_worktrees(struct worktree **); > /* > * Check if a per-worktree symref points to a ref in the main worktree > * or any linked worktree, and return the path to the exising worktree > - * if it is. Returns NULL if there is no existing ref. The caller is > - * responsible for freeing the returned path. > + * if it is. Returns NULL if there is no existing ref. The result > + * may be destroyed by the next call. > */ To return and keep alive one worktree[] instance (i.e. "existing"), the code holds onto the entire return value from get_worktrees(), if I am not misreading it. Typically you would have only a handful of worktrees so this may not be an issue, though.