All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v2 06/30] tests: fix ptimer leaks
Date: Tue, 21 Feb 2017 18:14:27 +0400	[thread overview]
Message-ID: <20170221141451.28305-7-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170221141451.28305-1-marcandre.lureau@redhat.com>

Spotted by ASAN.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/ptimer.h       |   1 +
 hw/core/ptimer.c          |   8 +++
 tests/ptimer-test-stubs.c |   5 ++
 tests/ptimer-test.c       | 122 ++++++++++++++++++++++++++++------------------
 4 files changed, 89 insertions(+), 47 deletions(-)

diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index 48cccbdb51..eafc3f0a86 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -60,6 +60,7 @@ typedef struct ptimer_state ptimer_state;
 typedef void (*ptimer_cb)(void *opaque);
 
 ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask);
+void ptimer_free(ptimer_state *s);
 void ptimer_set_period(ptimer_state *s, int64_t period);
 void ptimer_set_freq(ptimer_state *s, uint32_t freq);
 uint64_t ptimer_get_limit(ptimer_state *s);
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 3af82afe78..59ccb00550 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -12,6 +12,7 @@
 #include "qemu/host-utils.h"
 #include "sysemu/replay.h"
 #include "sysemu/qtest.h"
+#include "block/aio.h"
 
 #define DELTA_ADJUST     1
 #define DELTA_NO_ADJUST -1
@@ -353,3 +354,10 @@ ptimer_state *ptimer_init(QEMUBH *bh, uint8_t policy_mask)
     s->policy_mask = policy_mask;
     return s;
 }
+
+void ptimer_free(ptimer_state *s)
+{
+    qemu_bh_delete(s->bh);
+    timer_free(s->timer);
+    g_free(s);
+}
diff --git a/tests/ptimer-test-stubs.c b/tests/ptimer-test-stubs.c
index 21d4ebb0fe..8a1b0a336c 100644
--- a/tests/ptimer-test-stubs.c
+++ b/tests/ptimer-test-stubs.c
@@ -108,6 +108,11 @@ QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
     return bh;
 }
 
+void qemu_bh_delete(QEMUBH *bh)
+{
+    g_free(bh);
+}
+
 void replay_bh_schedule_event(QEMUBH *bh)
 {
     bh->cb(bh->opaque);
diff --git a/tests/ptimer-test.c b/tests/ptimer-test.c
index b36a476483..5d1a2a8188 100644
--- a/tests/ptimer-test.c
+++ b/tests/ptimer-test.c
@@ -73,6 +73,7 @@ static void check_set_count(gconstpointer arg)
     ptimer_set_count(ptimer, 1000);
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 1000);
     g_assert_false(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_set_limit(gconstpointer arg)
@@ -92,6 +93,7 @@ static void check_set_limit(gconstpointer arg)
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 2000);
     g_assert_cmpuint(ptimer_get_limit(ptimer), ==, 2000);
     g_assert_false(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_oneshot(gconstpointer arg)
@@ -194,6 +196,7 @@ static void check_oneshot(gconstpointer arg)
 
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
     g_assert_false(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_periodic(gconstpointer arg)
@@ -360,6 +363,7 @@ static void check_periodic(gconstpointer arg)
     g_assert_cmpuint(ptimer_get_count(ptimer), ==,
                     (no_round_down ? 8 : 7) + (wrap_policy ? 1 : 0));
     g_assert_false(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_on_the_fly_mode_change(gconstpointer arg)
@@ -406,6 +410,7 @@ static void check_on_the_fly_mode_change(gconstpointer arg)
 
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
     g_assert_true(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_on_the_fly_period_change(gconstpointer arg)
@@ -438,6 +443,7 @@ static void check_on_the_fly_period_change(gconstpointer arg)
 
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
     g_assert_true(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_on_the_fly_freq_change(gconstpointer arg)
@@ -470,6 +476,7 @@ static void check_on_the_fly_freq_change(gconstpointer arg)
 
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 0);
     g_assert_true(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_run_with_period_0(gconstpointer arg)
@@ -487,6 +494,7 @@ static void check_run_with_period_0(gconstpointer arg)
 
     g_assert_cmpuint(ptimer_get_count(ptimer), ==, 99);
     g_assert_false(triggered);
+    ptimer_free(ptimer);
 }
 
 static void check_run_with_delta_0(gconstpointer arg)
@@ -591,6 +599,7 @@ static void check_run_with_delta_0(gconstpointer arg)
     g_assert_true(triggered);
 
     ptimer_stop(ptimer);
+    ptimer_free(ptimer);
 }
 
 static void check_periodic_with_load_0(gconstpointer arg)
@@ -649,6 +658,7 @@ static void check_periodic_with_load_0(gconstpointer arg)
     }
 
     ptimer_stop(ptimer);
+    ptimer_free(ptimer);
 }
 
 static void check_oneshot_with_load_0(gconstpointer arg)
@@ -682,14 +692,14 @@ static void check_oneshot_with_load_0(gconstpointer arg)
     } else {
         g_assert_false(triggered);
     }
+
+    ptimer_free(ptimer);
 }
 
 static void add_ptimer_tests(uint8_t policy)
 {
-    uint8_t *ppolicy = g_malloc(1);
-    char *policy_name = g_malloc0(256);
-
-    *ppolicy = policy;
+    char policy_name[256] = "";
+    char *tmp;
 
     if (policy == PTIMER_POLICY_DEFAULT) {
         g_sprintf(policy_name, "default");
@@ -715,49 +725,67 @@ static void add_ptimer_tests(uint8_t policy)
         g_strlcat(policy_name, "no_counter_rounddown,", 256);
     }
 
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
-        ppolicy, check_set_count);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
-        ppolicy, check_set_limit);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
-        ppolicy, check_oneshot);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
-        ppolicy, check_periodic);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s", policy_name),
-        ppolicy, check_on_the_fly_mode_change);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s", policy_name),
-        ppolicy, check_on_the_fly_period_change);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s", policy_name),
-        ppolicy, check_on_the_fly_freq_change);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/run_with_period_0 policy=%s", policy_name),
-        ppolicy, check_run_with_period_0);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/run_with_delta_0 policy=%s", policy_name),
-        ppolicy, check_run_with_delta_0);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s", policy_name),
-        ppolicy, check_periodic_with_load_0);
-
-    g_test_add_data_func(
-        g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s", policy_name),
-        ppolicy, check_oneshot_with_load_0);
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/set_count policy=%s", policy_name),
+        g_memdup(&policy, 1), check_set_count, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/set_limit policy=%s", policy_name),
+        g_memdup(&policy, 1), check_set_limit, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/oneshot policy=%s", policy_name),
+        g_memdup(&policy, 1), check_oneshot, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/periodic policy=%s", policy_name),
+        g_memdup(&policy, 1), check_periodic, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/on_the_fly_mode_change policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_on_the_fly_mode_change, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/on_the_fly_period_change policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_on_the_fly_period_change, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/on_the_fly_freq_change policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_on_the_fly_freq_change, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/run_with_period_0 policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_run_with_period_0, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/run_with_delta_0 policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_run_with_delta_0, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/periodic_with_load_0 policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_periodic_with_load_0, g_free);
+    g_free(tmp);
+
+    g_test_add_data_func_full(
+        tmp = g_strdup_printf("/ptimer/oneshot_with_load_0 policy=%s",
+                              policy_name),
+        g_memdup(&policy, 1), check_oneshot_with_load_0, g_free);
+    g_free(tmp);
 }
 
 static void add_all_ptimer_policies_comb_tests(void)
-- 
2.11.0.295.gd7dffce1c.dirty

  parent reply	other threads:[~2017-02-21 14:15 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-21 14:14 [Qemu-devel] [PATCH v2 00/30] Various memory leak fixes Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 01/30] qtest: fix a memory leak Marc-André Lureau
2017-02-21 16:40   ` Philippe Mathieu-Daudé
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 02/30] tests: fix qmp response leak Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 03/30] tests: fix leaks in test-io-channel-command Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 04/30] timer: use an inline function for free Marc-André Lureau
2017-02-22 11:33   ` Paolo Bonzini
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 05/30] glib-compat: add g_test_add_data_func_full fallback Marc-André Lureau
2017-02-21 19:15   ` Eric Blake
2017-02-21 14:14 ` Marc-André Lureau [this message]
2017-02-22 11:33   ` [Qemu-devel] [PATCH v2 06/30] tests: fix ptimer leaks Paolo Bonzini
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 07/30] tests: fix endianness-test leaks Marc-André Lureau
2017-02-21 16:40   ` Philippe Mathieu-Daudé
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 08/30] tests: fix q35-test leaks Marc-André Lureau
2017-02-28 23:05   ` Eric Blake
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 09/30] tests: fix vhost-user-test leaks Marc-André Lureau
2017-02-28 23:09   ` Eric Blake
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 10/30] tests: fix ide-test leaks Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 11/30] tests: fix hd-geo-test leaks Marc-André Lureau
2017-02-27 13:59   ` Markus Armbruster
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 12/30] tests: fix bios-tables-test leak Marc-André Lureau
2017-02-27 14:03   ` Markus Armbruster
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 13/30] tests: fix ipmi-kcs-test leak Marc-André Lureau
2017-02-21 16:41   ` Philippe Mathieu-Daudé
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 14/30] tests: fix ipmi-bt-test leak Marc-André Lureau
2017-02-21 16:42   ` Philippe Mathieu-Daudé
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 15/30] pc: pcihp: avoid adding ACPI_PCIHP_PROP_BSEL twice Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 16/30] tests: fix eepro100-test leak Marc-André Lureau
2017-02-21 14:42   ` Stefan Weil
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 17/30] tests: fix tco-test leaks Marc-André Lureau
2017-02-28 23:10   ` Eric Blake
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 18/30] tests: fix e1000-test leak Marc-André Lureau
2017-02-21 16:42   ` Philippe Mathieu-Daudé
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 19/30] tests: fix i440fx-test leaks Marc-André Lureau
2017-02-27 14:05   ` Markus Armbruster
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 20/30] tests: fix e1000e leaks Marc-André Lureau
2017-02-27 14:12   ` Markus Armbruster
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 21/30] tests: fix virtio-scsi-test leak Marc-André Lureau
2017-02-22 11:33   ` Paolo Bonzini
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 22/30] tests: fix virtio-9p-test leaks Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 23/30] bus: do not unref hotplug handler Marc-André Lureau
2017-02-22 11:33   ` Paolo Bonzini
2017-02-22 13:03     ` Marc-André Lureau
2017-02-22 13:04       ` Paolo Bonzini
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 24/30] usb: replace handle_destroy with unrealize Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 25/30] usb: release the created buses Marc-André Lureau
2017-02-21 22:59   ` Gerd Hoffmann
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 26/30] tests: allows to run single test in usb-hcd-ehci-test Marc-André Lureau
2017-02-21 16:45   ` Philippe Mathieu-Daudé
2017-02-21 23:01   ` Gerd Hoffmann
2017-02-22  8:36     ` Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 27/30] tests: fix usb-test leaks Marc-André Lureau
2017-02-21 22:59   ` Gerd Hoffmann
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 28/30] tests: add specialized device_find function Marc-André Lureau
2017-02-28 23:21   ` Eric Blake
2017-03-01  7:59     ` Marc-André Lureau
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 29/30] tests: fix virtio-blk-test leaks Marc-André Lureau
2017-02-28 23:22   ` Eric Blake
2017-02-21 14:14 ` [Qemu-devel] [PATCH v2 30/30] migration: fix id leak regression Marc-André Lureau
2017-02-21 14:19   ` Dr. David Alan Gilbert
2017-02-21 17:04     ` Philippe Mathieu-Daudé
2017-02-22  8:41       ` Marc-André Lureau
2017-02-28  9:50   ` Dr. David Alan Gilbert
2017-02-27 11:04 ` [Qemu-devel] [PATCH v2 00/30] Various memory leak fixes Marc-André Lureau
2017-02-28 23:23   ` Eric Blake

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=20170221141451.28305-7-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@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.