[PATCH 0/2] Use g_autofree annotatins instead of VIR_FREE

Substitute VIR_FREE with g_autofree annotations in openvz_driver.c and node_device_driver.c whenever possible. The remaining instances of VIR_FREE are used to free return values in case of error. Kariiem (2): openvz_driver: use g_autofree instead of VIR_FREE in openvz_driver.c node_device: use g_autofree instead of VIR_FREE in node_device_driver.c src/node_device/node_device_driver.c | 4 +--- src/openvz/openvz_driver.c | 15 ++++----------- 2 files changed, 5 insertions(+), 14 deletions(-) -- 2.44.0

Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> --- src/openvz/openvz_driver.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 1bd96dfb56..fd3c25a393 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -615,7 +615,7 @@ openvzGenerateVethName(int veid, char *dev_name_ve) static char * openvzGenerateContainerVethName(int veid) { - char *temp = NULL; + g_autofree char *temp = NULL; char *name = NULL; /* try to get line "^NETIF=..." from config */ @@ -638,8 +638,6 @@ openvzGenerateContainerVethName(int veid) name = g_strdup_printf("eth%d", max + 1); } - VIR_FREE(temp); - return name; } @@ -750,7 +748,7 @@ openvzDomainSetNetworkConfig(virConnectPtr conn, { size_t i; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; - char *param; + g_autofree char *param = NULL; int first = 1; struct openvz_driver *driver = conn->privateData; @@ -774,12 +772,10 @@ openvzDomainSetNetworkConfig(virConnectPtr conn, param = virBufferContentAndReset(&buf); if (param) { if (openvzWriteVPSConfigParam(strtoI(def->name), "NETIF", param) < 0) { - VIR_FREE(param); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot replace NETIF config")); return -1; } - VIR_FREE(param); } } @@ -1075,7 +1071,7 @@ openvzDomainGetAutostart(virDomainPtr dom, int *autostart) { struct openvz_driver *driver = dom->conn->privateData; virDomainObj *vm; - char *value = NULL; + g_autofree char *value = NULL; int ret = -1; if (!(vm = openvzDomObjFromDomain(driver, dom->uuid))) @@ -1093,8 +1089,6 @@ openvzDomainGetAutostart(virDomainPtr dom, int *autostart) ret = 0; cleanup: - VIR_FREE(value); - virDomainObjEndAPI(&vm); return ret; } @@ -1405,7 +1399,7 @@ static int openvzConnectListDefinedDomains(virConnectPtr conn G_GNUC_UNUSED, static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) { FILE *fp; - char *line = NULL; + g_autofree char *line = NULL; size_t line_size = 0; unsigned long long usertime, systime, nicetime; int readvps = vpsid + 1; /* ensure readvps is initially different */ @@ -1442,7 +1436,6 @@ Version: 2.2 } } - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); if (err) return -1; -- 2.44.0

Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com> --- src/node_device/node_device_driver.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index ce42b1ca63..d99b48138e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -439,7 +439,7 @@ nodeDeviceListCaps(virNodeDevicePtr device, { virNodeDeviceObj *obj; virNodeDeviceDef *def; - virNodeDevCapType *list = NULL; + g_autofree virNodeDevCapType *list = NULL; int ncaps = 0; int ret = -1; size_t i = 0; @@ -472,8 +472,6 @@ nodeDeviceListCaps(virNodeDevicePtr device, for (j = 0; j < i; j++) VIR_FREE(names[j]); } - - VIR_FREE(list); return ret; } -- 2.44.0
participants (1)
-
Karim Taha