mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-16 00:21:28 +00:00
virSysinfoReadDMI: Use more g_auto*()
Virtually every variable defined in the function can be freed automatically when going out of scope. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
c66ccb65f6
commit
30ccd55338
@ -1119,10 +1119,10 @@ virSysinfoParseX86Memory(const char *base, virSysinfoDefPtr ret)
|
|||||||
virSysinfoDefPtr
|
virSysinfoDefPtr
|
||||||
virSysinfoReadDMI(void)
|
virSysinfoReadDMI(void)
|
||||||
{
|
{
|
||||||
char *path;
|
g_autofree char *path = NULL;
|
||||||
virSysinfoDefPtr ret = NULL;
|
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||||
char *outbuf = NULL;
|
g_autofree char *outbuf = NULL;
|
||||||
virCommandPtr cmd;
|
g_autoptr(virCommand) cmd = NULL;
|
||||||
|
|
||||||
path = virFindFileInPath(SYSINFO_SMBIOS_DECODER);
|
path = virFindFileInPath(SYSINFO_SMBIOS_DECODER);
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
@ -1133,48 +1133,38 @@ virSysinfoReadDMI(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNewArgList(path, "-q", "-t", "0,1,2,3,4,17", NULL);
|
cmd = virCommandNewArgList(path, "-q", "-t", "0,1,2,3,4,17", NULL);
|
||||||
VIR_FREE(path);
|
|
||||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
ret->type = VIR_SYSINFO_SMBIOS;
|
ret->type = VIR_SYSINFO_SMBIOS;
|
||||||
|
|
||||||
if (virSysinfoParseBIOS(outbuf, &ret->bios) < 0)
|
if (virSysinfoParseBIOS(outbuf, &ret->bios) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virSysinfoParseX86System(outbuf, &ret->system) < 0)
|
if (virSysinfoParseX86System(outbuf, &ret->system) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virSysinfoParseX86BaseBoard(outbuf, &ret->baseBoard, &ret->nbaseBoard) < 0)
|
if (virSysinfoParseX86BaseBoard(outbuf, &ret->baseBoard, &ret->nbaseBoard) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
if (virSysinfoParseX86Chassis(outbuf, &ret->chassis) < 0)
|
if (virSysinfoParseX86Chassis(outbuf, &ret->chassis) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
ret->nprocessor = 0;
|
ret->nprocessor = 0;
|
||||||
ret->processor = NULL;
|
ret->processor = NULL;
|
||||||
if (virSysinfoParseX86Processor(outbuf, ret) < 0)
|
if (virSysinfoParseX86Processor(outbuf, ret) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
ret->nmemory = 0;
|
ret->nmemory = 0;
|
||||||
ret->memory = NULL;
|
ret->memory = NULL;
|
||||||
if (virSysinfoParseX86Memory(outbuf, ret) < 0)
|
if (virSysinfoParseX86Memory(outbuf, ret) < 0)
|
||||||
goto error;
|
return NULL;
|
||||||
|
|
||||||
cleanup:
|
return g_steal_pointer(&ret);
|
||||||
VIR_FREE(outbuf);
|
|
||||||
virCommandFree(cmd);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virSysinfoDefFree(ret);
|
|
||||||
ret = NULL;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user