]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
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)
commit848a3b1d5bf49f92759143368942c7864066c03b
treeb868b5689bcaad78e6bbe11b426352e3b1240e29
parent6abd5ea124f173dd0bb68f6cdd1a175d103b517d
tests: avoid segfault if json monitor not present

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