Re: [PATCH 06/11] submodule--helper: add and use *_release() functions
- From
Glen Choo <chooglen@google.com>
- Date
- Jul 14, 2022, 18:11 UTC
- Message-ID
- <kl6lzghb4l8w.fsf@chooglen-macbookpro.roam.corp.google.com>
- In-Reply-To
- <patch-06.11-b9984e982db-20220713T131601Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 22 quoted lines
> Add release functions for "struct module_list", "struct
> submodule_update_clone" and "struct update_data". For now we're
> leaving some of the "struct update_data" members, we'll deal with
> those in a subsequent commit.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 2099c5774b2..a964dbeec38 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1910,6 +1921,13 @@ struct submodule_update_clone {
> };
> #define SUBMODULE_UPDATE_CLONE_INIT { 0 }
>
> +static void submodule_update_clone_release(struct submodule_update_clone *suc)
> +{
> + /* Not "update_data", owned by update_data_release() */
> + free(suc->update_clone);
> + free(suc->failed_clones);
> +}
> +To make this ownership clearer, should we also make submodule_update_clone.update_data const? i.e.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a964dbeec3..79fd901e5a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1906,7 +1906,7 @@ struct submodule_update_clone { int current; /* configuration parameters which are passed on to the children */ - struct update_data *update_data; + const struct update_data *update_data; /* to be consumed by update_submodule() */ struct update_clone_data *update_clone; @@ -2003,7 +2003,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, const char *update_string; enum submodule_update_type update_type; char *key; - struct update_data *ud = suc->update_data; + const struct update_data *ud = suc->update_data; char *displaypath = get_submodule_displaypath(ce->name, ud->prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0;