[libvirt] [PATCH v3 05/10] conf: Use VIR_AUTOFREE in domain_conf

Ján Tomko jtomko at redhat.com
Mon Mar 4 14:07:21 UTC 2019


On Fri, Mar 01, 2019 at 11:26:47AM -0500, John Ferlan wrote:
>Let's make use of the auto __cleanup capabilities for VIR_FREE consumers.
>In some cases adding or removing blank lines for readability.
>
>Signed-off-by: John Ferlan <jferlan at redhat.com>
>Reviewed-by: Erik Skultety <eskultet at redhat.com>
>---
> src/conf/domain_conf.c | 1080 +++++++++++++---------------------------
> 1 file changed, 347 insertions(+), 733 deletions(-)
>
>diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>index cbaa32e174..c06c52271c 100644
>--- a/src/conf/domain_conf.c
>+++ b/src/conf/domain_conf.c

[...]

>@@ -13468,8 +13263,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node,
>                                  virDomainGraphicsAuthDefPtr def,
>                                  int type)
> {
>-    char *validTo = NULL;
>-    char *connected = virXMLPropString(node, "connected");
>+    VIR_AUTOFREE(char *) validTo = NULL;
>+    VIR_AUTOFREE(char *) connected = virXMLPropString(node, "connected");
>
>     def->passwd = virXMLPropString(node, "passwd");
>
>@@ -13497,11 +13292,9 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node,
>             virReportError(VIR_ERR_INTERNAL_ERROR,
>                            _("cannot parse password validity time '%s', expect YYYY-MM-DDTHH:MM:SS"),
>                            validTo);
>-            VIR_FREE(validTo);
>             VIR_FREE(def->passwd);
>             return -1;

Nice, this would have leaked 'connected' before.

>         }
>-        VIR_FREE(validTo);
>
>         tm.tm_year -= 1900; /* Human epoch starts at 0 BC, not 1900BC */
>         tm.tm_mon--; /* Humans start months at 1, computers at 0 */
>@@ -13516,10 +13309,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node,
>             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                            _("unknown connected value %s"),
>                            connected);
>-            VIR_FREE(connected);
>             return -1;
>         }
>-        VIR_FREE(connected);
>
>         /* VNC supports connected='keep' only */
>         if (type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&

[...]

>@@ -14104,25 +13872,19 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def,
>                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                                    _("unknown spice channel name %s"),
>                                    name);
>-                    VIR_FREE(name);
>-                    VIR_FREE(mode);
>                     goto error;
>                 }
>                 if ((modeval = virDomainGraphicsSpiceChannelModeTypeFromString(mode)) < 0) {
>                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                                    _("unknown spice channel mode %s"),
>                                    mode);
>-                    VIR_FREE(name);
>-                    VIR_FREE(mode);
>                     goto error;
>                 }
>-                VIR_FREE(name);
>-                VIR_FREE(mode);

Nice to see these go.

>
>                 def->data.spice.channels[nameval] = modeval;
>             } else if (virXMLNodeNameEqual(cur, "image")) {
>-                char *compression = virXMLPropString(cur, "compression");
>                 int compressionVal;
>+                VIR_AUTOFREE(char *) compression = virXMLPropString(cur, "compression");
>
>                 if (!compression) {
>                     virReportError(VIR_ERR_INTERNAL_ERROR, "%s",

[...]

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190304/cd0843f7/attachment-0001.sig>


More information about the libvir-list mailing list