qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Qemu-trivial] [PATCH] test: Use g_strndup instead of plain strndup
@ 2019-06-07 14:07 tony.nguyen
  2019-06-07 15:09 ` Markus Armbruster
  0 siblings, 1 reply; 2+ messages in thread
From: tony.nguyen @ 2019-06-07 14:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial, armbru

Due to memory management rules. See HACKING.
    
Signed-off-by: Tony Nguyen <tony.nguyen@bt.com>

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);
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;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] test: Use g_strndup instead of plain strndup
  2019-06-07 14:07 [Qemu-devel] [Qemu-trivial] [PATCH] test: Use g_strndup instead of plain strndup tony.nguyen
@ 2019-06-07 15:09 ` Markus Armbruster
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Armbruster @ 2019-06-07 15:09 UTC (permalink / raw)
  To: tony.nguyen; +Cc: qemu-trivial, qemu-devel

<tony.nguyen@bt.com> writes:

> Due to memory management rules. See HACKING.
>     
> Signed-off-by: Tony Nguyen <tony.nguyen@bt.com>
>
> 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().


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-07 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07 14:07 [Qemu-devel] [Qemu-trivial] [PATCH] test: Use g_strndup instead of plain strndup tony.nguyen
2019-06-07 15:09 ` Markus Armbruster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).