qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Correct win32 timers deleting v.3
@ 2011-01-26  8:06 Pavel Dovgaluk
  2011-02-02 11:59 ` Pavel Dovgaluk
       [not found] ` <20128.8864635446$1296660564@news.gmane.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Pavel Dovgaluk @ 2011-01-26  8:06 UTC (permalink / raw)
  To: qemu-devel

This patch fixes resource leaks caused by quitting qemu with exit() function on
win32 host.
Timer object should be freed not only at the end of the main function, but by
every of the application exits.

v.3: Fixed all the issues found in previous messages with patch.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@gmail.com>
---
 qemu-timer.c |   16 +++++++++++++---
 vl.c         |    1 -
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 95814af..86d77a6 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -972,7 +972,10 @@ static int win32_start_timer(struct qemu_alarm_timer *t)
     timeGetDevCaps(&tc, sizeof(tc));
 
     data->period = tc.wPeriodMin;
-    timeBeginPeriod(data->period);
+    if (timeBeginPeriod(data->period) != TIMERR_NOERROR) {
+        fprintf(stderr, "Failed to initialize win32 alarm timer\n");
+        return -1;
+    }
 
     flags = TIME_CALLBACK_FUNCTION;
     if (alarm_has_dynticks(t))
@@ -990,6 +993,7 @@ static int win32_start_timer(struct qemu_alarm_timer *t)
         fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n",
                 GetLastError());
         timeEndPeriod(data->period);
+        data->period = 0;
         return -1;
     }
 
@@ -1000,8 +1004,12 @@ static void win32_stop_timer(struct qemu_alarm_timer *t)
 {
     struct qemu_alarm_win32 *data = t->priv;
 
-    timeKillEvent(data->timerId);
-    timeEndPeriod(data->period);
+    if (data->timerId) {
+        timeKillEvent(data->timerId);
+    }
+    if (data->period) {
+        timeEndPeriod(data->period);
+    }
 }
 
 static void win32_rearm_timer(struct qemu_alarm_timer *t)
@@ -1027,6 +1035,7 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t)
                 GetLastError());
 
         timeEndPeriod(data->period);
+        data->period = 0;
         exit(1);
     }
 }
@@ -1061,6 +1070,7 @@ int init_timer_alarm(void)
     t->pending = 1;
     alarm_timer = t;
     qemu_add_vm_change_state_handler(alarm_timer_on_change_state_rearm, t);
+    atexit(quit_timers);
 
     return 0;
 
diff --git a/vl.c b/vl.c
index 0292184..c4b25b0 100644
--- a/vl.c
+++ b/vl.c
@@ -3118,7 +3118,6 @@ int main(int argc, char **argv, char **envp)
     os_setup_post();
 
     main_loop();
-    quit_timers();
     net_cleanup();
 
     return 0;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [Qemu-devel] [PATCH] Correct win32 timers deleting v.3
  2011-01-26  8:06 [Qemu-devel] [PATCH] Correct win32 timers deleting v.3 Pavel Dovgaluk
@ 2011-02-02 11:59 ` Pavel Dovgaluk
       [not found] ` <20128.8864635446$1296660564@news.gmane.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Pavel Dovgaluk @ 2011-02-02 11:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan.Weil

Hello.

 Anybody interested in this patch?

Pavel Dovgaluk

> -----Original Message-----
> From: qemu-devel-bounces+pavel.dovgaluk=ispras.ru@nongnu.org [mailto:qemu-
> devel-bounces+pavel.dovgaluk=ispras.ru@nongnu.org] On Behalf Of Pavel
> Dovgaluk
> Sent: Wednesday, January 26, 2011 11:06 AM
> To: qemu-devel@nongnu.org
> Subject: [Qemu-devel] [PATCH] Correct win32 timers deleting v.3
> 
> This patch fixes resource leaks caused by quitting qemu with exit()
> function on
> win32 host.
> Timer object should be freed not only at the end of the main function, but
> by
> every of the application exits.
> 
> v.3: Fixed all the issues found in previous messages with patch.
> 
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@gmail.com>
> ---
>  qemu-timer.c |   16 +++++++++++++---
>  vl.c         |    1 -
>  2 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 95814af..86d77a6 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -972,7 +972,10 @@ static int win32_start_timer(struct qemu_alarm_timer
> *t)
>      timeGetDevCaps(&tc, sizeof(tc));
> 
>      data->period = tc.wPeriodMin;
> -    timeBeginPeriod(data->period);
> +    if (timeBeginPeriod(data->period) != TIMERR_NOERROR) {
> +        fprintf(stderr, "Failed to initialize win32 alarm timer\n");
> +        return -1;
> +    }
> 
>      flags = TIME_CALLBACK_FUNCTION;
>      if (alarm_has_dynticks(t))
> @@ -990,6 +993,7 @@ static int win32_start_timer(struct qemu_alarm_timer
> *t)
>          fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n",
>                  GetLastError());
>          timeEndPeriod(data->period);
> +        data->period = 0;
>          return -1;
>      }
> 
> @@ -1000,8 +1004,12 @@ static void win32_stop_timer(struct qemu_alarm_timer
> *t)
>  {
>      struct qemu_alarm_win32 *data = t->priv;
> 
> -    timeKillEvent(data->timerId);
> -    timeEndPeriod(data->period);
> +    if (data->timerId) {
> +        timeKillEvent(data->timerId);
> +    }
> +    if (data->period) {
> +        timeEndPeriod(data->period);
> +    }
>  }
> 
>  static void win32_rearm_timer(struct qemu_alarm_timer *t)
> @@ -1027,6 +1035,7 @@ static void win32_rearm_timer(struct qemu_alarm_timer
> *t)
>                  GetLastError());
> 
>          timeEndPeriod(data->period);
> +        data->period = 0;
>          exit(1);
>      }
>  }
> @@ -1061,6 +1070,7 @@ int init_timer_alarm(void)
>      t->pending = 1;
>      alarm_timer = t;
>      qemu_add_vm_change_state_handler(alarm_timer_on_change_state_rearm,
> t);
> +    atexit(quit_timers);
> 
>      return 0;
> 
> diff --git a/vl.c b/vl.c
> index 0292184..c4b25b0 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3118,7 +3118,6 @@ int main(int argc, char **argv, char **envp)
>      os_setup_post();
> 
>      main_loop();
> -    quit_timers();
>      net_cleanup();
> 
>      return 0;
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: [PATCH] Correct win32 timers deleting v.3
       [not found] ` <20128.8864635446$1296660564@news.gmane.org>
@ 2011-02-10  9:49   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2011-02-10  9:49 UTC (permalink / raw)
  To: Pavel Dovgaluk; +Cc: Stefan.Weil, qemu-devel

On 02/02/2011 12:59 PM, Pavel Dovgaluk wrote:
> Hello.
>
>   Anybody interested in this patch?

I'm planning to replace the multimedia timer with a queue timer.  I'll 
send the patch soon(ish).

Paolo

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-02-10  9:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-26  8:06 [Qemu-devel] [PATCH] Correct win32 timers deleting v.3 Pavel Dovgaluk
2011-02-02 11:59 ` Pavel Dovgaluk
     [not found] ` <20128.8864635446$1296660564@news.gmane.org>
2011-02-10  9:49   ` [Qemu-devel] " Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).