[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/23] util/qemu-timer: Make timer_free() imply timer_del()
From: |
Peter Maydell |
Subject: |
[PULL 09/23] util/qemu-timer: Make timer_free() imply timer_del() |
Date: |
Fri, 8 Jan 2021 15:36:07 +0000 |
Currently timer_free() is a simple wrapper for g_free(). This means
that the timer being freed must not be currently active, as otherwise
QEMU might crash later when the active list is processed and still
has a pointer to freed memory on it. As a result almost all calls to
timer_free() are preceded by a timer_del() call, as can be seen in
the output of
git grep -B1 '\<timer_free\>'
This is unfortunate API design as it makes it easy to accidentally
misuse (by forgetting the timer_del()), and the correct use is
annoyingly verbose.
Make timer_free() imply a timer_del().
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20201215154107.3255-2-peter.maydell@linaro.org
---
include/qemu/timer.h | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index bdecc5b41fe..61296ea980c 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -609,17 +609,6 @@ static inline QEMUTimer *timer_new_ms(QEMUClockType type,
QEMUTimerCB *cb,
*/
void timer_deinit(QEMUTimer *ts);
-/**
- * timer_free:
- * @ts: the timer
- *
- * Free a timer (it must not be on the active list)
- */
-static inline void timer_free(QEMUTimer *ts)
-{
- g_free(ts);
-}
-
/**
* timer_del:
* @ts: the timer
@@ -631,6 +620,19 @@ static inline void timer_free(QEMUTimer *ts)
*/
void timer_del(QEMUTimer *ts);
+/**
+ * timer_free:
+ * @ts: the timer
+ *
+ * Free a timer. This will call timer_del() for you to remove
+ * the timer from the active list if it was still active.
+ */
+static inline void timer_free(QEMUTimer *ts)
+{
+ timer_del(ts);
+ g_free(ts);
+}
+
/**
* timer_mod_ns:
* @ts: the timer
--
2.20.1
- [PULL 00/23] target-arm queue, Peter Maydell, 2021/01/08
- [PULL 01/23] intc/arm_gic: Fix gic_irq_signaling_enabled() for vCPUs, Peter Maydell, 2021/01/08
- [PULL 02/23] hw/arm/virt: Remove virt machine state 'smp_cpus', Peter Maydell, 2021/01/08
- [PULL 03/23] target/arm: Fix MTE0_ACTIVE, Peter Maydell, 2021/01/08
- [PULL 04/23] hw/intc/armv7m_nvic: Correct handling of CCR.BFHFNMIGN, Peter Maydell, 2021/01/08
- [PULL 05/23] target/arm: Correct store of FPSCR value via FPCXT_S, Peter Maydell, 2021/01/08
- [PULL 06/23] target/arm: Implement FPCXT_NS fp system register, Peter Maydell, 2021/01/08
- [PULL 07/23] target/arm: Implement Cortex-M55 model, Peter Maydell, 2021/01/08
- [PULL 08/23] hw/arm/highbank: Drop dead KVM support code, Peter Maydell, 2021/01/08
- [PULL 10/23] scripts/coccinelle: New script to remove unnecessary timer_del() calls, Peter Maydell, 2021/01/08
- [PULL 09/23] util/qemu-timer: Make timer_free() imply timer_del(),
Peter Maydell <=
- [PULL 12/23] target/arm: Remove timer_del()/timer_deinit() before timer_free(), Peter Maydell, 2021/01/08
- [PULL 11/23] Remove superfluous timer_del() calls, Peter Maydell, 2021/01/08
- [PULL 14/23] allwinner-a10-pit: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 16/23] exynos4210_pwm: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 13/23] digic-timer: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 17/23] mss-timer: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 19/23] exynos4210_mct: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 18/23] musicpal: Use ptimer_free() in the finalize function to avoid memleaks, Peter Maydell, 2021/01/08
- [PULL 20/23] hw/misc: imx6_ccm: Update PMU_MISC0 reset value, Peter Maydell, 2021/01/08
- [PULL 21/23] hw/msic: imx6_ccm: Correct register value for silicon type, Peter Maydell, 2021/01/08