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

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

 



Ævar Arnfjörð Bjarmason  <avarab@xxxxxxxxx> writes:

> 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>
> ---
>  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.





[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