qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH] test: Use g_strndup instead of p


From: Markus Armbruster
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] test: Use g_strndup instead of plain strndup
Date: Fri, 07 Jun 2019 17:09:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

<address@hidden> writes:

> Due to memory management rules. See HACKING.
>     
> Signed-off-by: Tony Nguyen <address@hidden>
>
> diff --git a/tests/check-qjson.c b/tests/check-qjson.c
> index fa2afcc..07a773e 100644
> --- a/tests/check-qjson.c
> +++ b/tests/check-qjson.c
> @@ -767,7 +767,7 @@ static void utf8_string(void)
>                      if (*end == ' ') {
>                          end++;
>                      }
> -                    in = strndup(tail, end - tail);
> +                    in = g_strndup(tail, end - tail);
>                      str = from_json_str(in, j, NULL);
>                      g_assert(!str);
>                      g_free(in);

This one is fine.

> diff --git a/tests/migration/stress.c b/tests/migration/stress.c
> index 49a03aa..72c4012 100644
> --- a/tests/migration/stress.c
> +++ b/tests/migration/stress.c
> @@ -104,7 +104,7 @@ static int get_command_arg_str(const char *name,
>      }
>  
>      if (end)
> -        *val = strndup(start, end - start);
> +        *val = g_strndup(start, end - start);
>      else
>          *val = strdup(start);
>      return 1;

This one isn't.  The caller passes *val to free().  You have to change
*both* allocations in get_command_arg_str() *and* the deallocation in
get_command_arg_ull().



reply via email to

[Prev in Thread] Current Thread [Next in Thread]