rollback_packed_refs(): take a `packed_ref_store *` parameter
[gitweb.git] / worktree.c
index c1ec334b06f8b8d55b4087d1208d85731fd46543..726f732e5ecf92824c06b9f7a7dda82dfadf79f5 100644 (file)
@@ -209,16 +209,19 @@ struct worktree *find_worktree(struct worktree **list,
 {
        struct worktree *wt;
        char *path;
+       char *to_free = NULL;
 
        if ((wt = find_worktree_by_suffix(list, arg)))
                return wt;
 
-       arg = prefix_filename(prefix, strlen(prefix), arg);
+       if (prefix)
+               arg = to_free = prefix_filename(prefix, arg);
        path = real_pathdup(arg, 1);
        for (; *list; list++)
                if (!fspathcmp(path, real_path((*list)->path)))
                        break;
        free(path);
+       free(to_free);
        return *list;
 }