[PATCH 03/12] util: xml: Refactor cleanup path in virXMLValidatorInit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Automatically free 'validator' on errors.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virxml.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 35c0340779..e9595da97d 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1608,7 +1608,7 @@ virXMLValidatorRNGErrorIgnore(void *ctx G_GNUC_UNUSED,
 virXMLValidator *
 virXMLValidatorInit(const char *schemafile)
 {
-    virXMLValidator *validator = NULL;
+    g_autoptr(virXMLValidator) validator = NULL;

     validator = g_new0(virXMLValidator, 1);

@@ -1619,7 +1619,7 @@ virXMLValidatorInit(const char *schemafile)
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to create RNG parser for %s"),
                        validator->schemafile);
-        goto error;
+        return NULL;
     }

     xmlRelaxNGSetParserErrors(validator->rngParser,
@@ -1632,25 +1632,22 @@ virXMLValidatorInit(const char *schemafile)
                        _("Unable to parse RNG %s: %s"),
                        validator->schemafile,
                        virBufferCurrentContent(&validator->buf));
-        goto error;
+        return NULL;
     }

     if (!(validator->rngValid = xmlRelaxNGNewValidCtxt(validator->rng))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unable to create RNG validation context %s"),
                        validator->schemafile);
-        goto error;
+        return NULL;
     }

     xmlRelaxNGSetValidErrors(validator->rngValid,
                              virXMLValidatorRNGErrorCatch,
                              virXMLValidatorRNGErrorIgnore,
                              &validator->buf);
-    return validator;

- error:
-    virXMLValidatorFree(validator);
-    return NULL;
+    return g_steal_pointer(&validator);
 }


-- 
2.38.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux