]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: avoid crash on process attach
authorEric Blake <eblake@redhat.com>
Thu, 4 Aug 2011 20:07:58 +0000 (14:07 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 4 Aug 2011 20:18:14 +0000 (14:18 -0600)
Detected by ccc-analyzer, reported by Alex Jia.

qemuProcessStart always calls qemuProcessWaitForMonitor with a
non-negative position, but qemuProcessAttach always calls with -1.
In the latter case, there is no log file we can scrape, so we
also should not be trying to scrape the logs if the qemu process
died at the very end.

* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Don't try
to read from log in qemuProcessAttach case.

src/qemu/qemu_process.c

index b0d2149881fa261a964a2b0bf48adf07efd18933..30c8b28f5e1f251ea244d62b272fe4d42c8064a7 100644 (file)
@@ -1214,7 +1214,7 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
 cleanup:
     virHashFree(paths);
 
-    if (kill(vm->pid, 0) == -1 && errno == ESRCH) {
+    if (pos != -1 && kill(vm->pid, 0) == -1 && errno == ESRCH) {
         /* VM is dead, any other error raised in the interim is probably
          * not as important as the qemu cmdline output */
         qemuProcessReadLogFD(logfd, buf, buf_size, strlen(buf));
@@ -1225,8 +1225,6 @@ cleanup:
     }
 
 closelog:
-    VIR_FREE(buf);
-
     if (VIR_CLOSE(logfd) < 0) {
         char ebuf[1024];
         VIR_WARN("Unable to close logfile: %s",