All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Kamil Dudka <kdudka@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] qtest: do not return freed argument vector from qtest_rsp
Date: Fri, 20 Nov 2020 14:09:12 +0100	[thread overview]
Message-ID: <87zh3c41l3.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20201120073149.99079-1-pbonzini@redhat.com> (Paolo Bonzini's message of "Fri, 20 Nov 2020 08:31:49 +0100")

Paolo Bonzini <pbonzini@redhat.com> writes:

> If expected_args is 0, qtest frees the argument vector and then returns it
> nevertheless.  Coverity complains; in practice this is not an issue because
> expected_args == 0 means that the caller is not interested in the argument
> vector, but it would be a potential problem if somebody wanted to add
> commands with optional arguments to qtest.
>
> Suggested-by: Kamil Dudka <kdudka@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  tests/qtest/libqtest.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index be0fb430dd..e49f3a1e45 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -545,6 +545,7 @@ redo:
       if (expected_args) {
           for (i = 0; i < expected_args; i++) {
               g_assert(words[i] != NULL);
>          }
>      } else {
>          g_strfreev(words);
> +        words = NULL;
>      }
>  
>      return words;

The patch is okay, so

Reviewed-by: Markus Armbruster <armbru@redhat.com>

Odd: we require at least @expected_args, but more is fine.  Not what the
name @expected_args made me expect.

We treat expected_args == 0 as special case to save callers the trouble
to free @words.  Okay, but I'd try a more regular interface:

* one function that takes @expected_args and returns @words, always.

* a simple wrapper around it that passes zero @expected_args and frees
  @words.



      parent reply	other threads:[~2020-11-20 13:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  7:31 [PATCH] qtest: do not return freed argument vector from qtest_rsp Paolo Bonzini
2020-11-20 12:38 ` Thomas Huth
2020-11-20 13:09 ` Markus Armbruster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zh3c41l3.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=kdudka@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.