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

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

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 1, 2022, 09:24 UTC
Message-ID
<220701.86k08xb2w4.gmgdl@evledraar.gmail.com>
In-Reply-To
<CAPig+cT5jETAi5extz2tHwSzp4a=b7qqaK0S=mcjQr1m_1jAQQ@mail.gmail.com>
On Fri, Jul 01 2022, Eric Sunshine wrote:
Show 25 quoted lines
> On Thu, Jun 30, 2022 at 7:51 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> 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>
>> ---
>> diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
>> @@ -294,11 +294,13 @@ static int protect_ntfs_hfs_benchmark(int argc, const char **argv)
>>  int cmd__path_utils(int argc, const char **argv)
>>  {
>>         if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
>> -               char *buf = xmallocz(strlen(argv[2]));
>> +               char *to_free = NULL;
>> +               char *buf = to_free = xmallocz(strlen(argv[2]));
>
> Is there a non-obvious reason that `to_free` is initialized to NULL
> before being immediately overwritten with the result of xmallocz()?
>
> Also, pure nit, but it may be a bit more idiomatic (though I could be
> wrong) written as:
>
>     char *buf, *to_free;
>     buf = to_free = xmallocz(...);

Thanks, I'll change it to be like that. I wouldn't put "= NULL" there normally, that part snuck in from some earlier version, and escaped my own pre-review.

Previous: Eric SunshineNext: Ævar Arnfjörð Bjarmason
Message 5 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.