Skip to content

Commit

Permalink
vl.c: remove init_clocks call from main
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
batuzovk authored and stefanhaRH committed May 9, 2014
1 parent b1e6fc0 commit 02ce232
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 3 additions & 0 deletions qemu-timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 02ce232

Please sign in to comment.