On Mon, Feb 5, 2018 at 6:55 PM, Stefan Beller <[email protected]> wrote:
> Both fetch and push still use alternates to access submodules in some
> other code paths, but this is progress towards eliminating the alternates
> hack that conflates access to the_repository and other repositories.
>
> Signed-off-by: Jonathan Nieder <[email protected]>
> Signed-off-by: Stefan Beller <[email protected]>
> ---
> diff --git a/submodule.c b/submodule.c
> @@ -832,24 +833,43 @@ static int check_has_commit(const struct object_id
> *oid, void *data)
> +static int open_submodule(struct repository *out, const char *path)
> +{
> + struct strbuf sb = STRBUF_INIT;
> +
> + if (submodule_to_gitdir(&sb, path))
> + return -1;
submodule_to_gitdir() makes no promise that it has not made
allocations to 'sb' when it returns -1, so this is potentially
leaking. Therefore, you should strbuf_release() here.
> +
> + if (repo_init(out, sb.buf, NULL)) {
> + strbuf_release(&sb);
> + return -1;
> + }
Or just combine these two error cases:
if (submodule_to_gitdir(...) || repo_init(...)) {
strbuf_release(...);
return -1;
}
> + out->submodule_prefix = xstrdup(path);
> +
> + strbuf_release(&sb);
> + return 0;
> +}