Skip to content

Commit 02ce232

Browse files
batuzovkstefanhaRH
authored andcommitted
vl.c: remove init_clocks call from main
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 <[email protected]> Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent b1e6fc0 commit 02ce232

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

qemu-timer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ static void qemu_clock_init(QEMUClockType type)
126126
{
127127
QEMUClock *clock = qemu_clock_ptr(type);
128128

129+
/* Assert that the clock of type TYPE has not been initialized yet. */
130+
assert(main_loop_tlg.tl[type] == NULL);
131+
129132
clock->type = type;
130133
clock->enabled = true;
131134
clock->last = INT64_MIN;

vl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,6 @@ int main(int argc, char **argv, char **envp)
30243024

30253025
runstate_init();
30263026

3027-
init_clocks();
30283027
rtc_clock = QEMU_CLOCK_HOST;
30293028

30303029
qemu_init_auxval(envp);

0 commit comments

Comments
 (0)