]> xenbits.xensource.com Git - libvirt.git/commitdiff
virSecretLoad: Simplify cleanup path
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 16 Oct 2023 08:03:28 +0000 (10:03 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Oct 2023 06:32:24 +0000 (08:32 +0200)
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 <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/virsecretobj.c

index 2585b2c9729d471633726a4e241436c9117781c3..455798d414c674a3df4c2dd346325a64a724a639 100644 (file)
@@ -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;
 }