From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wiq5i-0008La-8G for qemu-devel@nongnu.org; Fri, 09 May 2014 15:04:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wiq5d-0005tq-Ib for qemu-devel@nongnu.org; Fri, 09 May 2014 15:04:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37478) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wiq5d-0005tl-9i for qemu-devel@nongnu.org; Fri, 09 May 2014 15:04:13 -0400 From: Stefan Hajnoczi Date: Fri, 9 May 2014 21:03:31 +0200 Message-Id: <1399662217-31148-12-git-send-email-stefanha@redhat.com> In-Reply-To: <1399662217-31148-1-git-send-email-stefanha@redhat.com> References: <1399662217-31148-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 11/17] vl.c: remove init_clocks call from main List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi , Kirill Batuzov From: Kirill Batuzov Clocks are initialized in qemu_init_main_loop. They are not needed before it. Initializing them twice is not only unnecessary but is harmful: it results in memory leak and potentially can lead to a situation where different parts of QEMU use different sets of timers. To avoid it remove init_clocks call from main and add an assertion to qemu_clock_init that corresponding clock has not been initialized yet. Signed-off-by: Kirill Batuzov Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 3 +++ vl.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/qemu-timer.c b/qemu-timer.c index 9be1a41..00a5d35 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -126,6 +126,9 @@ static void qemu_clock_init(QEMUClockType type) { QEMUClock *clock = qemu_clock_ptr(type); + /* Assert that the clock of type TYPE has not been initialized yet. */ + assert(main_loop_tlg.tl[type] == NULL); + clock->type = type; clock->enabled = true; clock->last = INT64_MIN; diff --git a/vl.c b/vl.c index 73e0661..709d8cd 100644 --- a/vl.c +++ b/vl.c @@ -3024,7 +3024,6 @@ int main(int argc, char **argv, char **envp) runstate_init(); - init_clocks(); rtc_clock = QEMU_CLOCK_HOST; qemu_init_auxval(envp); -- 1.9.0