qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 2/7] block/gluster: Use g_autofree for string in qemu_gluster


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 2/7] block/gluster: Use g_autofree for string in qemu_gluster_parse_json()
Date: Wed, 31 Jul 2024 22:54:41 +0200
User-agent: Mozilla Thunderbird

On 31/7/24 16:36, Peter Maydell wrote:
In the loop in qemu_gluster_parse_json() we do:

     char *str = NULL;
     for(...) {
         str = g_strdup_printf(...);
         ...
         if (various errors) {
             goto out;
         }
         ...
         g_free(str);
         str = NULL;
     }
     return 0;
out:
     various cleanups;
     g_free(str);
     ...
     return -errno;

Coverity correctly complains that the assignment "str = NULL" at the
end of the loop is unnecessary, because we will either go back to the
top of the loop and overwrite it, or else we will exit the loop and
then exit the function without ever reading str again. The assignment
is there as defensive coding to ensure that str is only non-NULL if
it's a live allocation, so this is intentional.

We can make Coverity happier and simplify the code here by using
g_autofree, since we never need 'str' outside the loop.

Resolves: Coverity CID 1527385
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
  block/gluster.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>




reply via email to

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