Re: [PATCH 09/11] submodule--helper: free "char *" in "struct update_data"
- From
Glen Choo <chooglen@google.com>
- Date
- Jul 14, 2022, 18:33 UTC
- Message-ID
- <kl6ltu7j4k98.fsf@chooglen-macbookpro.roam.corp.google.com>
- In-Reply-To
- <patch-09.11-7b36f71879e-20220713T131601Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Make the update_data_release() function free the "recursive_prefix" > and "displaypath" members when appropriate. For the former it could > come from either "argv" or from our own allocation, so we need to keep > track of a "to_free" sibling seperately.
Obsolete message probably? "recursive_prefix" no longer exists as of gc/submodule-use-super-prefix ;)
> For "displaypath" it's always ours, so the "const char *" type was > wrong to begin with, it should be a "char *" instead.
Ok.
> For update_submodule() we'll free() these as we go along, it's called > in a loop by update_submodules(), and we'll need to free the "last" > one.
Hm, I don't follow this part. Does "as we go along" mean "as we go along freeing things in update_submodules()", or "we'll do this later on"?
I'm assuming it's the latter since this patch only frees the "last" one and doesn't free inside of update_submodule(), but maybe it's not so hard to do? I think it's just:
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 0bac39880d..34b54e97d1 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2560,6 +2560,7 @@ static int update_submodule(struct update_data *update_data)
{
ensure_core_worktree(update_data->sm_path); + free(update_data->displaypath);
update_data->displaypath = get_submodule_displaypath(
update_data->sm_path, update_data->prefix);Show 28 quoted lines
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> builtin/submodule--helper.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 2b44f391f15..0bac39880d2 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1949,7 +1949,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc)
>
> struct update_data {
> const char *prefix;
> - const char *displaypath;
> + char *displaypath;
> enum submodule_update_type update_default;
> struct object_id suboid;
> struct string_list references;
> @@ -1987,6 +1987,7 @@ struct update_data {
>
> static void update_data_release(struct update_data *ud)
> {
> + free(ud->displaypath);
> module_list_release(&ud->list);
> }
>
> --
> 2.37.0.932.g7b7031e73bc