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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 30, 2022 at 7:51 PM Ævar Arnfjörð Bjarmason
<avarab@xxxxxxxxx> 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@xxxxxxxxx>
> ---
> 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(...);



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux