t0302 & t3900: add forgotten quotes
[gitweb.git] / worktree.c
index fa7bc67a50a6d52116b0ca994b473668998f1c3f..89a81b13de38473aaa52870d80f59c247578a3a5 100644 (file)
@@ -250,16 +250,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;
 }
 
@@ -396,6 +399,7 @@ int submodule_uses_worktrees(const char *path)
 
        /* The env would be set for the superproject. */
        get_common_dir_noenv(&sb, submodule_gitdir);
+       free(submodule_gitdir);
 
        /*
         * The check below is only known to be good for repository format
@@ -415,7 +419,6 @@ int submodule_uses_worktrees(const char *path)
        /* See if there is any file inside the worktrees directory. */
        dir = opendir(sb.buf);
        strbuf_release(&sb);
-       free(submodule_gitdir);
 
        if (!dir)
                return 0;