monitor: Cleanup mon->outbuf on write error
authorStratos Psomadakis <psomas@grnet.gr>
Mon, 27 Jan 2014 10:30:15 +0000 (12:30 +0200)
committerLuiz Capitulino <lcapitulino@redhat.com>
Tue, 28 Jan 2014 17:47:12 +0000 (12:47 -0500)
In case monitor_flush() fails to write the contents of mon->outbuf to
the output device, mon->outbuf is not cleaned up properly. Check the
return code of the qemu_chr_fe_write() function and cleanup the outbuf
if it fails.

References: http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg02890.html

Signed-off-by: Stratos Psomadakis <psomas@grnet.gr>
Signed-off-by: Dimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
monitor.c

index 80456fbe5b01f8633e4a43ce21ec7183ce5572d6..cba56bc4b70eb5e16454fc0cb3a3f8228c4432af 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -288,8 +288,8 @@ void monitor_flush(Monitor *mon)
 
     if (len && !mon->mux_out) {
         rc = qemu_chr_fe_write(mon->chr, (const uint8_t *) buf, len);
-        if (rc == len) {
-            /* all flushed */
+        if ((rc < 0 && errno != EAGAIN) || (rc == len)) {
+            /* all flushed or error */
             QDECREF(mon->outbuf);
             mon->outbuf = qstring_new();
             return;