qemuMonitorPtr mon;
+ char *tmpdir;
+
size_t nitems;
qemuMonitorTestItemPtr *items;
qemuMonitorTestItemFree(test->items[i]);
VIR_FREE(test->items);
+ if (test->tmpdir && rmdir(test->tmpdir) < 0)
+ VIR_WARN("Failed to remove tempdir: %s", strerror(errno));
+
+ VIR_FREE(test->tmpdir);
+
virMutexDestroy(&test->lock);
VIR_FREE(test);
}
{
qemuMonitorTestPtr test = NULL;
virDomainChrSourceDef src;
+ char *path = NULL;
+ char *tmpdir_template = NULL;
- char *tmpdir = NULL, *path = NULL;
- char template[] = "/tmp/libvirt_XXXXXX";
-
- tmpdir = mkdtemp(template);
- if (tmpdir == NULL) {
- virReportSystemError(errno, "%s",
- "Failed to create temporary directory");
- goto error;
- }
-
- if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", tmpdir) < 0) {
- virReportOOMError();
- goto error;
- }
-
- memset(&src, 0, sizeof(src));
- src.type = VIR_DOMAIN_CHR_TYPE_UNIX;
- src.data.nix.path = (char *)path;
- src.data.nix.listen = false;
-
- if (VIR_ALLOC(test) < 0) {
- virReportOOMError();
- return NULL;
- }
+ if (VIR_ALLOC(test) < 0)
+ goto no_memory;
if (virMutexInit(&test->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
+ if (!(tmpdir_template = strdup("/tmp/libvirt_XXXXXX")))
+ goto no_memory;
+
+ if (!(test->tmpdir = mkdtemp(tmpdir_template))) {
+ virReportSystemError(errno, "%s",
+ "Failed to create temporary directory");
+ goto error;
+ }
+
+ tmpdir_template = NULL;
+
+ if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
+ goto no_memory;
+
test->json = json;
if (!(test->vm = virDomainObjNew(caps)))
goto error;
&test->server) < 0)
goto error;
+ memset(&src, 0, sizeof(src));
+ src.type = VIR_DOMAIN_CHR_TYPE_UNIX;
+ src.data.nix.path = (char *)path;
+ src.data.nix.listen = false;
if (virNetSocketListen(test->server, 1) < 0)
goto error;
virMutexUnlock(&test->lock);
cleanup:
- if (tmpdir)
- if (rmdir(tmpdir) < 0)
- VIR_WARN("Failed to remove tempdir: %s", strerror(errno));
VIR_FREE(path);
return test;
+no_memory:
+ virReportOOMError();
+
error:
+ VIR_FREE(tmpdir_template);
qemuMonitorTestFree(test);
goto cleanup;
}