git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/6] grep: prefer "struct grep_opt" over its "void *"

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 21, 2021, 23:52 UTC
Message-ID
<xmqqv91qey1d.fsf@gitster.g>
In-Reply-To
<patch-1.6-2bdd21e4e59-20211021T155529Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
> Subject: Re: [PATCH 1/6] grep: prefer "struct grep_opt" over its "void *"

I sense an incomplete sentence. "counterpart" or "equivalent" is missing at the tail, perhaps?

> Stylistically fix up code added in bfac23d9534 (grep: Fix two memory
> leaks, 2010-01-30). We usually don't use the "arg" at all once we've
> unpacked it into the struct we want, let's not do that here when we're

As we do not unpack and instead take it as a whole and cast, "we've unpacked it into" -> "we've casted it to".

Show 23 quoted lines
> freeing it. Perhaps it was thought that a cast to "void *" would
> otherwise be needed?
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/grep.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 8af5249a7bb..fd184c182a3 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -199,8 +199,8 @@ static void *run(void *arg)
>  		grep_source_clear_data(&w->source);
>  		work_done(w);
>  	}
> -	free_grep_patterns(arg);
> -	free(arg);
> +	free_grep_patterns(opt);
> +	free(opt);
>  
>  	return (void*) (intptr_t) hit;
>  }
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 20 in “leaks: miscellaneous small leak fixes”
  1. 0/6 leaks: miscellaneous small leak fixesÆvar Arnfjörð Bjarmason, Oct 21, 2021
  2. 1/6 grep: prefer "struct grep_opt" over its "void *"Ævar Arnfjörð Bjarmason, Oct 21, 2021
  3. Junio C HamanoOct 21, 2021
  4. 2/6 grep: use object_array_clear() in cmd_grep()Ævar Arnfjörð Bjarmason, Oct 21, 2021
  5. Junio C HamanoOct 21, 2021
  6. Junio C HamanoOct 21, 2021
  7. 3/6 clone: fix a memory leak of the "git_dir" variableÆvar Arnfjörð Bjarmason, Oct 21, 2021
  8. Junio C HamanoOct 22, 2021
  9. 4/6 submodule--helper: fix small memory leaksÆvar Arnfjörð Bjarmason, Oct 21, 2021
  10. 5/6 reflog: free() ref given to us by dwim_log()Ævar Arnfjörð Bjarmason, Oct 21, 2021
  11. Junio C HamanoOct 22, 2021
  12. 6/6 repack: stop leaking a "struct child_process"Ævar Arnfjörð Bjarmason, Oct 21, 2021
  13. Junio C HamanoOct 22, 2021
  14. 0/6 leaks: miscellaneous small leak fixesÆvar Arnfjörð Bjarmason, Oct 22, 2021
  15. 1/6 grep: prefer "struct grep_opt" over its "void *" equivalentÆvar Arnfjörð Bjarmason, Oct 22, 2021
  16. 2/6 grep: use object_array_clear() in cmd_grep()Ævar Arnfjörð Bjarmason, Oct 22, 2021
  17. 3/6 grep: fix a "path_list" memory leakÆvar Arnfjörð Bjarmason, Oct 22, 2021
  18. 4/6 clone: fix a memory leak of the "git_dir" variableÆvar Arnfjörð Bjarmason, Oct 22, 2021
  19. 5/6 submodule--helper: fix small memory leaksÆvar Arnfjörð Bjarmason, Oct 22, 2021
  20. 6/6 reflog: free() ref given to us by dwim_log()Ævar Arnfjörð Bjarmason, Oct 22, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.