Junio C Hamano <[email protected]> writes:

> From: Junio C Hamano <[email protected]>
> Date: Fri, 1 Apr 2016 12:23:16 -0700
> Subject: [PATCH] submodule--helper: do not borrow absolute_path() result for 
> too long
>
> absolute_path() is designed to allow its callers to take a brief
> peek of the result (typically, to be fed to functions like
> strbuf_add() and relative_path() as a parameter) without having to
> ...
> @@ -199,8 +198,7 @@ static int module_clone(int argc, const char **argv, 
> const char *prefix)
>               die(_("submodule--helper: unspecified or empty --path"));
>  
>       strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
> -     sm_gitdir_rel = strbuf_detach(&sb, NULL);
> -     sm_gitdir = absolute_path(sm_gitdir_rel);
> +     sm_gitdir = xstrdup(absolute_path(sb.buf));

Just to prevent others from wasting time scratching their heads,
we need

        strbuf_reset(&sb);

here, as the strbuf will be reused later and is expected to be empty
at this point.

>  
>       if (!is_absolute_path(path)) {
>               strbuf_addf(&sb, "%s/%s", get_git_work_tree(), path);
> @@ -245,7 +243,7 @@ static int module_clone(int argc, const char **argv, 
> const char *prefix)
>                              relative_path(path, sm_gitdir, &rel_path));
>       strbuf_release(&sb);
>       strbuf_release(&rel_path);
> -     free(sm_gitdir_rel);
> +     free(sm_gitdir);
>       free(path);
>       free(p);
>       return 0;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to