mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 23:07:44 +00:00
capabilities: use g_autofree in capabilities.c
Use g_autofree in capabilities.c for some pointers still using manual cleanup, and remove unnecessary cleanup. Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c90ee1441f
commit
c341df33ac
@ -1489,15 +1489,14 @@ virCapabilitiesGetNUMADistances(int node,
|
|||||||
virNumaDistance **distancesRet,
|
virNumaDistance **distancesRet,
|
||||||
int *ndistancesRet)
|
int *ndistancesRet)
|
||||||
{
|
{
|
||||||
virNumaDistance *tmp = NULL;
|
g_autofree virNumaDistance *tmp = NULL;
|
||||||
int tmp_size = 0;
|
int tmp_size = 0;
|
||||||
int ret = -1;
|
g_autofree int *distances = NULL;
|
||||||
int *distances = NULL;
|
|
||||||
int ndistances = 0;
|
int ndistances = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (virNumaGetDistances(node, &distances, &ndistances) < 0)
|
if (virNumaGetDistances(node, &distances, &ndistances) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!distances) {
|
if (!distances) {
|
||||||
*distancesRet = NULL;
|
*distancesRet = NULL;
|
||||||
@ -1521,11 +1520,8 @@ virCapabilitiesGetNUMADistances(int node,
|
|||||||
*ndistancesRet = tmp_size;
|
*ndistancesRet = tmp_size;
|
||||||
*distancesRet = g_steal_pointer(&tmp);
|
*distancesRet = g_steal_pointer(&tmp);
|
||||||
tmp_size = 0;
|
tmp_size = 0;
|
||||||
ret = 0;
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FREE(distances);
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1533,13 +1529,12 @@ virCapabilitiesGetNUMAPagesInfo(int node,
|
|||||||
virCapsHostNUMACellPageInfo **pageinfo,
|
virCapsHostNUMACellPageInfo **pageinfo,
|
||||||
int *npageinfo)
|
int *npageinfo)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree unsigned int *pages_size = NULL;
|
||||||
unsigned int *pages_size = NULL;
|
g_autofree unsigned long long *pages_avail = NULL;
|
||||||
unsigned long long *pages_avail = NULL;
|
|
||||||
size_t npages, i;
|
size_t npages, i;
|
||||||
|
|
||||||
if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < 0)
|
if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
*pageinfo = g_new0(virCapsHostNUMACellPageInfo, npages);
|
*pageinfo = g_new0(virCapsHostNUMACellPageInfo, npages);
|
||||||
*npageinfo = npages;
|
*npageinfo = npages;
|
||||||
@ -1549,12 +1544,7 @@ virCapabilitiesGetNUMAPagesInfo(int node,
|
|||||||
(*pageinfo)[i].avail = pages_avail[i];
|
(*pageinfo)[i].avail = pages_avail[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(pages_avail);
|
|
||||||
VIR_FREE(pages_size);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2034,22 +2024,18 @@ virCapabilitiesHostNUMANewHost(void)
|
|||||||
int
|
int
|
||||||
virCapabilitiesInitPages(virCaps *caps)
|
virCapabilitiesInitPages(virCaps *caps)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree unsigned int *pages_size = NULL;
|
||||||
unsigned int *pages_size = NULL;
|
|
||||||
size_t npages;
|
size_t npages;
|
||||||
|
|
||||||
if (virNumaGetPages(-1 /* Magic constant for overall info */,
|
if (virNumaGetPages(-1 /* Magic constant for overall info */,
|
||||||
&pages_size, NULL, NULL, &npages) < 0)
|
&pages_size, NULL, NULL, &npages) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
caps->host.pagesSize = g_steal_pointer(&pages_size);
|
caps->host.pagesSize = g_steal_pointer(&pages_size);
|
||||||
caps->host.nPagesSize = npages;
|
caps->host.nPagesSize = npages;
|
||||||
npages = 0;
|
npages = 0;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
VIR_FREE(pages_size);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user