]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: avoid segfault if json monitor not present
authorEric Blake <eblake@redhat.com>
Fri, 22 Feb 2013 21:56:21 +0000 (14:56 -0700)
committerEric Blake <eblake@redhat.com>
Tue, 26 Feb 2013 00:37:14 +0000 (17:37 -0700)
On a machine without yajl headers, I was seeing random segfaults
from qemumonitorjsontest (about 90% of the runs on my particular
machine).  The segfault was inside virClassIsDerivedFrom, which
points to a case of a race leading to unreferencing a stale
pointer to an object that had already been freed.  I also noticed
that if I got the segfault, I was seeing messages such as:

2013-02-22 16:12:37.504+0000: 19833: error : virNetSocketWriteWire:1361 : Cannot write data: Bad file descriptor

which is also evidence of deferencing a stale pointer.  I traced it
to a race where qemuMonitorTestIO could execute late, after the
main thread had already called qemuMonitorTestFree and called
virNetSocketClose(test->client) but not clearing it out to NULL.
Sure enough, after test->client has been closed, fd is -1, which
causes an attempt to write to the socket to fail, which in turn
triggers the error code of qemuMonitorTestIO that tries to re-close
test->client.

* tests/qemumonitortestutils.c (qemuMonitorTestIO): Don't attempt
to free client again if test already quit.

tests/qemumonitortestutils.c

index 1ed42ce91bba292b24cb052977cecf7f9dbaf31c..979623a244403a0c3ac7839593cf47ad461fbf48 100644 (file)
@@ -214,6 +214,10 @@ static void qemuMonitorTestIO(virNetSocketPtr sock,
     bool err = false;
 
     virMutexLock(&test->lock);
+    if (test->quit) {
+        virMutexUnlock(&test->lock);
+        return;
+    }
     if (events & VIR_EVENT_HANDLE_WRITABLE) {
         ssize_t ret;
         if ((ret = virNetSocketWrite(sock,