[PATCH] conf: domain_conf: cleanup def in case of errors

Shaleen Bathla posted 1 patch 3 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20240111125754.2873514-1-shaleen.bathla@oracle.com
src/conf/domain_conf.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[PATCH] conf: domain_conf: cleanup def in case of errors
Posted by Shaleen Bathla 3 months, 2 weeks ago
Just like in rest of the function virDomainFSDefParseXML,
use goto error so that def will be cleaned up in error cases.

Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
---
 src/conf/domain_conf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index be57a1981e7d..5d55d2acdace 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8866,23 +8866,23 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
             goto error;
 
         if ((n = virXPathNodeSet("./idmap/uid", ctxt, &uid_nodes)) < 0)
-            return NULL;
+            goto error;
 
         if (n) {
             def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, uid_nodes, n);
             if (!def->idmap.uidmap)
-                return NULL;
+                goto error;
 
             def->idmap.nuidmap = n;
         }
 
         if ((n = virXPathNodeSet("./idmap/gid", ctxt, &gid_nodes)) < 0)
-            return NULL;
+            goto error;
 
         if (n) {
             def->idmap.gidmap = virDomainIdmapDefParseXML(ctxt, gid_nodes, n);
             if (!def->idmap.gidmap)
-                return NULL;
+                goto error;
 
             def->idmap.ngidmap = n;
         }
-- 
2.39.3
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH] conf: domain_conf: cleanup def in case of errors
Posted by Jonathon Jongsma 3 months, 2 weeks ago
On 1/11/24 6:57 AM, Shaleen Bathla wrote:
> Just like in rest of the function virDomainFSDefParseXML,
> use goto error so that def will be cleaned up in error cases.
> 
> Signed-off-by: Shaleen Bathla <shaleen.bathla@oracle.com>
> ---
>   src/conf/domain_conf.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index be57a1981e7d..5d55d2acdace 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -8866,23 +8866,23 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt,
>               goto error;
>   
>           if ((n = virXPathNodeSet("./idmap/uid", ctxt, &uid_nodes)) < 0)
> -            return NULL;
> +            goto error;
>   
>           if (n) {
>               def->idmap.uidmap = virDomainIdmapDefParseXML(ctxt, uid_nodes, n);
>               if (!def->idmap.uidmap)
> -                return NULL;
> +                goto error;
>   
>               def->idmap.nuidmap = n;
>           }
>   
>           if ((n = virXPathNodeSet("./idmap/gid", ctxt, &gid_nodes)) < 0)
> -            return NULL;
> +            goto error;
>   
>           if (n) {
>               def->idmap.gidmap = virDomainIdmapDefParseXML(ctxt, gid_nodes, n);
>               if (!def->idmap.gidmap)
> -                return NULL;
> +                goto error;
>   
>               def->idmap.ngidmap = n;
>           }

It might be worthwhile to introduce an automatic cleanup function for 
virDomainFSDef and remove the gotos from this function completely, but 
this patch fixes the immediate issue.

Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>

_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org