mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
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.
This commit is contained in:
parent
6abd5ea124
commit
848a3b1d5b
@ -214,6 +214,10 @@ static void qemuMonitorTestIO(virNetSocketPtr sock,
|
|||||||
bool err = false;
|
bool err = false;
|
||||||
|
|
||||||
virMutexLock(&test->lock);
|
virMutexLock(&test->lock);
|
||||||
|
if (test->quit) {
|
||||||
|
virMutexUnlock(&test->lock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
if ((ret = virNetSocketWrite(sock,
|
if ((ret = virNetSocketWrite(sock,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user