qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Li Qiang <liq3ea@163.com>,
	vyasevic@redhat.com, dgilbert@redhat.com, mst@redhat.com,
	jasowang@redhat.com
Cc: liq3ea@gmail.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] tests: test-announce-self: fix memory leak
Date: Mon, 11 Mar 2019 09:29:23 +0100	[thread overview]
Message-ID: <2f636abc-34be-97a4-8375-3c4e0cdbabff@redhat.com> (raw)
In-Reply-To: <20190310131205.75856-1-liq3ea@163.com>

On 10/03/2019 14.12, Li Qiang wrote:
> Spotted by ASAN when 'make check'.
> 
> Signed-off-by: Li Qiang <liq3ea@163.com>
> ---
>  tests/test-announce-self.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
> 
> diff --git a/tests/test-announce-self.c b/tests/test-announce-self.c
> index 1644d34a3f..3f370d8bf5 100644
> --- a/tests/test-announce-self.c
> +++ b/tests/test-announce-self.c
> @@ -21,17 +21,6 @@
>  #define ETH_P_RARP 0x8035
>  #endif
>  
> -static QTestState *test_init(int socket)
> -{
> -    char *args;
> -
> -    args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
> -                           "virtio-net-pci,netdev=hs0", socket);
> -
> -    return qtest_start(args);
> -}
> -
> -
>  static void test_announce(int socket)
>  {
>      char buffer[60];
> @@ -58,19 +47,22 @@ static void test_announce(int socket)
>  
>  static void setup(gconstpointer data)
>  {
> -    QTestState *qs;
>      void (*func) (int socket) = data;
>      int sv[2], ret;
> +    char *args;
>  
>      ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
>      g_assert_cmpint(ret, !=, -1);
>  
> -    qs = test_init(sv[1]);
> +    args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
> +                           "virtio-net-pci,netdev=hs0", sv[1]);
> +    qtest_start(args);

Actually, we don't need the g_strdup_printf and the args variable here
at all - it's cleaner and easier to use qtest_initf() here. Could you to
change your patch to look something like this:

diff a/tests/test-announce-self.c b/tests/test-announce-self.c
--- a/tests/test-announce-self.c
+++ b/tests/test-announce-self.c
@@ -21,18 +21,8 @@
 #define ETH_P_RARP 0x8035
 #endif

-static QTestState *test_init(int socket)
-{
-    char *args;
-
-    args = g_strdup_printf("-netdev socket,fd=%d,id=hs0 -device "
-                           "virtio-net-pci,netdev=hs0", socket);
-
-    return qtest_start(args);
-}
-

-static void test_announce(int socket)
+static void test_announce(QTestState *qs, int socket)
 {
     char buffer[60];
     int len;
@@ -40,7 +30,7 @@ static void test_announce(int socket)
     int ret;
     uint16_t *proto = (uint16_t *)&buffer[12];

-    rsp = qmp("{ 'execute' : 'announce-self', "
+    rsp = qtest_qmp(qs, "{ 'execute' : 'announce-self', "
                   " 'arguments': {"
                       " 'initial': 50, 'max': 550,"
                       " 'rounds': 10, 'step': 50 } }");
@@ -59,14 +49,15 @@ static void test_announce(int socket)
 static void setup(gconstpointer data)
 {
     QTestState *qs;
-    void (*func) (int socket) = data;
+    void (*func) (QTestState *qs, int socket) = data;
     int sv[2], ret;

     ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv);
     g_assert_cmpint(ret, !=, -1);

-    qs = test_init(sv[1]);
-    func(sv[0]);
+    qs = qtest_initf("-netdev socket,fd=%d,id=hs0 -device "
+                           "virtio-net-pci,netdev=hs0", sv[1]);
+    func(qs, sv[0]);

     /* End test */
     close(sv[0]);

 Thanks,
  Thomas

      reply	other threads:[~2019-03-11  8:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-10 13:12 [Qemu-devel] [PATCH] tests: test-announce-self: fix memory leak Li Qiang
2019-03-11  8:29 ` Thomas Huth [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=2f636abc-34be-97a4-8375-3c4e0cdbabff@redhat.com \
    --to=thuth@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=liq3ea@163.com \
    --cc=liq3ea@gmail.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vyasevic@redhat.com \
    /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 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).