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

Re: [PATCH v2 2/9] test-tool path-utils: fix a memory leak

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 1, 2022, 20:43 UTC
Message-ID
<xmqq5ykg8syr.fsf@gitster.g>
In-Reply-To
<patch-v2-2.9-050766e6fa2-20220701T103503Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 23 quoted lines
> Fix a memory leak in "test-tool path-utils", as a result we can mark
> the corresponding test as passing with SANITIZE=leak using
> "TEST_PASSES_SANITIZE_LEAK=true".
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/helper/test-path-utils.c | 11 +++++++----
>  t/t0060-path-utils.sh      |  1 +
>  2 files changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
> index 229ed416b0e..d20e1b7a18d 100644
> --- a/t/helper/test-path-utils.c
> +++ b/t/helper/test-path-utils.c
> @@ -296,9 +296,8 @@ int cmd__path_utils(int argc, const char **argv)
>  	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
>  		char *buf = xmallocz(strlen(argv[2]));
>  		int rv = normalize_path_copy(buf, argv[2]);
> -		if (rv)
> -			buf = "++failed++";
> -		puts(buf);
> +		puts(rv ? "++failed++" : buf);
> +		free(buf);

This version, without the need for to_free, is certainly very easy to understand. Nicely done.

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 19 of 26 in “test-tool: fix memory leaks”
  1. 0/9 test-tool: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  2. 3/9 test-tool {dump,scrap}-cache-tree: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  3. 2/9 test-tool path-utils: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  4. Eric SunshineJul 1, 2022
  5. Ævar Arnfjörð BjarmasonJul 1, 2022
  6. 1/9 test-tool test-hash: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  7. 8/9 test-tool ref-store: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  8. 4/9 test-tool urlmatch-normalization: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  9. 5/9 test-tool regex: call regfree(), fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  10. Junio C HamanoJul 1, 2022
  11. 7/9 test-tool bloom: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  12. Eric SunshineJul 1, 2022
  13. Ævar Arnfjörð BjarmasonJul 1, 2022
  14. 9/9 test-tool delta: fix a memory leakÆvar Arnfjörð Bjarmason, Jun 30, 2022
  15. 6/9 test-tool json-writer: fix memory leaksÆvar Arnfjörð Bjarmason, Jun 30, 2022
  16. 0/9 test-tool: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  17. 1/9 test-tool test-hash: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  18. 2/9 test-tool path-utils: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  19. Junio C HamanoJul 1, 2022
  20. 3/9 test-tool {dump,scrap}-cache-tree: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  21. 4/9 test-tool urlmatch-normalization: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  22. 5/9 test-tool regex: call regfree(), fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  23. 6/9 test-tool json-writer: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  24. 7/9 test-tool bloom: fix memory leaksÆvar Arnfjörð Bjarmason, Jul 1, 2022
  25. 8/9 test-tool ref-store: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022
  26. 9/9 test-tool delta: fix a memory leakÆvar Arnfjörð Bjarmason, Jul 1, 2022

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.