From 2a88b51edffedc089f60f7adaa79dd95f5eace55 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 16 Oct 2023 10:03:28 +0200 Subject: [PATCH] virSecretLoad: Simplify cleanup path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When loading a secret value fails, the control jumps over to the 'cleanup' label where explicit call to virSecretDefFree() happens. This is unnecessary as the corresponding variable can be declared with g_autoptr() after which all error paths can just return NULL instantly. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/virsecretobj.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 2585b2c972..455798d414 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -865,25 +865,24 @@ virSecretLoad(virSecretObjList *secrets, const char *path, const char *configDir) { - virSecretDef *def = NULL; + g_autoptr(virSecretDef) def = NULL; virSecretObj *obj = NULL; if (!(def = virSecretDefParse(NULL, path, 0))) - goto cleanup; + return NULL; if (virSecretLoadValidateUUID(def, file) < 0) - goto cleanup; + return NULL; if (!(obj = virSecretObjListAdd(secrets, &def, configDir, NULL))) - goto cleanup; + return NULL; if (virSecretLoadValue(obj) < 0) { virSecretObjListRemove(secrets, obj); g_clear_pointer(&obj, virObjectUnref); + return NULL; } - cleanup: - virSecretDefFree(def); return obj; }