ch: use g_auto in virCHMonitorNew

Also introduces a G_DEFINE_AUTOPTR_CLEANUP_FUNC for virCHMonitor.

Signed-off-by: William Douglas <william.douglas@intel.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
William Douglas 2021-10-01 11:12:37 -07:00 committed by Laine Stump
parent 9e99f84328
commit 13fc1432c6
2 changed files with 8 additions and 14 deletions

View File

@ -444,9 +444,8 @@ chMonitorCreateSocket(const char *socket_path)
virCHMonitor *
virCHMonitorNew(virDomainObj *vm, const char *socketdir)
{
virCHMonitor *ret = NULL;
virCHMonitor *mon = NULL;
virCommand *cmd = NULL;
g_autoptr(virCHMonitor) mon = NULL;
g_autoptr(virCommand) cmd = NULL;
int socket_fd = 0;
if (virCHMonitorInitialize() < 0)
@ -458,7 +457,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
if (!vm->def) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("VM is not defined"));
goto cleanup;
return NULL;
}
/* prepare to launch Cloud-Hypervisor socket */
@ -467,7 +466,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
virReportSystemError(errno,
_("Cannot create socket directory '%s'"),
socketdir);
goto cleanup;
return NULL;
}
cmd = virCommandNew(vm->def->emulator);
@ -477,7 +476,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
virReportSystemError(errno,
_("Cannot create socket '%s'"),
mon->socketpath);
goto cleanup;
return NULL;
}
virCommandAddArg(cmd, "--api-socket");
@ -486,7 +485,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
/* launch Cloud-Hypervisor socket */
if (virCommandRunAsync(cmd, &mon->pid) < 0)
goto cleanup;
return NULL;
/* get a curl handle */
mon->handle = curl_easy_init();
@ -494,13 +493,7 @@ virCHMonitorNew(virDomainObj *vm, const char *socketdir)
/* now has its own reference */
mon->vm = virObjectRef(vm);
ret = mon;
mon = NULL;
cleanup:
virCHMonitorClose(mon);
virCommandFree(cmd);
return ret;
return g_steal_pointer(&mon);
}
static void virCHMonitorDispose(void *opaque)

View File

@ -53,6 +53,7 @@ struct _virCHMonitor {
virCHMonitor *virCHMonitorNew(virDomainObj *vm, const char *socketdir);
void virCHMonitorClose(virCHMonitor *mon);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCHMonitor, virCHMonitorClose);
int virCHMonitorCreateVM(virCHMonitor *mon);
int virCHMonitorBootVM(virCHMonitor *mon);