]> xenbits.xensource.com Git - libvirt.git/commitdiff
virTypedParamsValidate: Refactor variable declaration and cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 19 Apr 2023 08:37:09 +0000 (10:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 2 May 2023 12:32:46 +0000 (14:32 +0200)
Use automatic memory cleanup for the 'keys' and 'sorted' helpers and
remove the 'cleanup' label. Since this patch is modifying variable
declarations ensure that all declarations conform with our coding style.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virtypedparam.c

index ee1b095bf9a919b0f6a214a32c719bce4a58e1ac..73b9420e5e047df577d1f7e592d379b1c4c3f04f 100644 (file)
@@ -59,12 +59,15 @@ int
 virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
 {
     va_list ap;
-    int ret = -1;
-    size_t i, j;
-    const char *name, *last_name = NULL;
+    size_t i;
+    size_t j;
+    const char *name;
+    const char *last_name = NULL;
     int type;
-    size_t nkeys = 0, nkeysalloc = 0;
-    virTypedParameterPtr sorted = NULL, keys = NULL;
+    size_t nkeys = 0;
+    size_t nkeysalloc = 0;
+    g_autofree virTypedParameterPtr sorted = NULL;
+    g_autofree virTypedParameterPtr keys = NULL;
 
     va_start(ap, nparams);
 
@@ -82,7 +85,8 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
         if (virStrcpyStatic(keys[nkeys].field, name) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Field name '%1$s' too long"), name);
-            goto cleanup;
+            va_end(ap);
+            return -1;
         }
 
         keys[nkeys].type = type & ~VIR_TYPED_PARAM_MULTIPLE;
@@ -93,6 +97,8 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
         name = va_arg(ap, const char *);
     }
 
+    va_end(ap);
+
     qsort(keys, nkeys, sizeof(*keys), virTypedParamsSortName);
 
     for (i = 0, j = 0; i < nparams && j < nkeys;) {
@@ -104,7 +110,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
                 virReportError(VIR_ERR_INVALID_ARG,
                                _("parameter '%1$s' occurs multiple times"),
                                sorted[i].field);
-                goto cleanup;
+                return -1;
             }
             if (sorted[i].type != keys[j].type) {
                 const char *badtype;
@@ -116,7 +122,7 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
                                _("invalid type '%1$s' for parameter '%2$s', expected '%3$s'"),
                                badtype, sorted[i].field,
                                virTypedParameterTypeToString(keys[j].type));
-                goto cleanup;
+                return -1;
             }
             last_name = sorted[i].field;
             i++;
@@ -127,15 +133,10 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
         virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
                        _("parameter '%1$s' not supported"),
                        sorted[i].field);
-        goto cleanup;
+        return -1;
     }
 
-    ret = 0;
- cleanup:
-    va_end(ap);
-    VIR_FREE(sorted);
-    VIR_FREE(keys);
-    return ret;
+    return 0;
 }