Use g_autofree in capabilities.c for some pointers still using manual cleanup,
and remove unnecessary cleanup.
Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/conf/capabilities.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 1a7ebf4a13..e498c77efc 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -1489,15 +1489,14 @@ virCapabilitiesGetNUMADistances(int node,
virNumaDistance **distancesRet,
int *ndistancesRet)
{
- virNumaDistance *tmp = NULL;
+ g_autofree virNumaDistance *tmp = NULL;
int tmp_size = 0;
- int ret = -1;
- int *distances = NULL;
+ g_autofree int *distances = NULL;
int ndistances = 0;
size_t i;
if (virNumaGetDistances(node, &distances, &ndistances) < 0)
- goto cleanup;
+ return -1;
if (!distances) {
*distancesRet = NULL;
@@ -1521,11 +1520,8 @@ virCapabilitiesGetNUMADistances(int node,
*ndistancesRet = tmp_size;
*distancesRet = g_steal_pointer(&tmp);
tmp_size = 0;
- ret = 0;
- cleanup:
- VIR_FREE(distances);
- VIR_FREE(tmp);
- return ret;
+
+ return 0;
}
static int
@@ -1533,13 +1529,12 @@ virCapabilitiesGetNUMAPagesInfo(int node,
virCapsHostNUMACellPageInfo **pageinfo,
int *npageinfo)
{
- int ret = -1;
- unsigned int *pages_size = NULL;
- unsigned long long *pages_avail = NULL;
+ g_autofree unsigned int *pages_size = NULL;
+ g_autofree unsigned long long *pages_avail = NULL;
size_t npages, i;
if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) <
0)
- goto cleanup;
+ return -1;
*pageinfo = g_new0(virCapsHostNUMACellPageInfo, npages);
*npageinfo = npages;
@@ -1549,12 +1544,7 @@ virCapabilitiesGetNUMAPagesInfo(int node,
(*pageinfo)[i].avail = pages_avail[i];
}
- ret = 0;
-
- cleanup:
- VIR_FREE(pages_avail);
- VIR_FREE(pages_size);
- return ret;
+ return 0;
}
@@ -2034,22 +2024,18 @@ virCapabilitiesHostNUMANewHost(void)
int
virCapabilitiesInitPages(virCaps *caps)
{
- int ret = -1;
- unsigned int *pages_size = NULL;
+ g_autofree unsigned int *pages_size = NULL;
size_t npages;
if (virNumaGetPages(-1 /* Magic constant for overall info */,
&pages_size, NULL, NULL, &npages) < 0)
- goto cleanup;
+ return -1;
caps->host.pagesSize = g_steal_pointer(&pages_size);
caps->host.nPagesSize = npages;
npages = 0;
- ret = 0;
- cleanup:
- VIR_FREE(pages_size);
- return ret;
+ return 0;
}
--
2.33.0
Show replies by date
On 10/15/22 11:18, Jiang Jiacheng wrote:
Use g_autofree in capabilities.c for some pointers still using manual
cleanup,
and remove unnecessary cleanup.
Signed-off-by: Jiang Jiacheng <jiangjiacheng(a)huawei.com>
---
src/conf/capabilities.c | 38 ++++++++++++--------------------------
1 file changed, 12 insertions(+), 26 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn(a)redhat.com>
and pushed.
Michal