Patchwork [FOR,0.12] monitor: Catch printing to non-existent monitor

login
register
mail settings
Submitter Luiz Capitulino
Date Dec. 3, 2009, 7:02 p.m.
Message ID <20091203170241.6a8f0451@doriath>
Download mbox | patch
Permalink /patch/40217/
State New
Headers show

Comments

Luiz Capitulino - Dec. 3, 2009, 7:02 p.m.
The monitor_vprintf() function now touches the 'mon' variable
before calling monitor_puts(), this causes block migration
to segfault as its functions call monitor_printf() with a
NULL 'mon'.

This is probably hiding the real bug, but for some reason this
has been the behavior for a long time.

We also change monitor_print_object() to use monitor_print(),
so that monitor_puts() is only called by monitor_vprintf().

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Patch

diff --git a/monitor.c b/monitor.c
index b035e0b..6d0b1dd 100644
--- a/monitor.c
+++ b/monitor.c
@@ -171,9 +171,6 @@  static void monitor_puts(Monitor *mon, const char *str)
 {
     char c;
 
-    if (!mon)
-        return;
-
     for(;;) {
         c = *str++;
         if (c == '\0')
@@ -189,6 +186,9 @@  static void monitor_puts(Monitor *mon, const char *str)
 
 void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
 {
+    if (!mon)
+        return;
+
     if (mon->mc && !mon->mc->print_enabled) {
         qemu_error_new(QERR_UNDEFINED_ERROR);
     } else {
@@ -269,7 +269,7 @@  static void monitor_print_qobject(Monitor *mon, const QObject *data)
             break;
     }
 
-    monitor_puts(mon, "\n");
+    monitor_printf(mon, "\n");
 }
 
 static void monitor_json_emitter(Monitor *mon, const QObject *data)