Re: [PATCH 09/12] virSecurityDeviceLabelDefParseXML: Use automatic memory clearing for temp strings

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

 



On Mon, Nov 22, 2021 at 18:12:29 +0100, Peter Krempa wrote:
> Apart from code simplification the refactor of 'model' fixes an unlikely
> memory leak of the string if a duplicate model is found.
> 
> While the coversion of 'label' variable may seem unnecessary it will
> come in handy in the next patch.
> 
> Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index bd9da0744d..e829511ac5 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -8016,7 +8016,10 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
>      size_t nseclabels = 0;
>      int n;
>      size_t i, j;
> -    char *model, *relabel, *label, *labelskip;
> +    g_autofree char *model = NULL;
> +    g_autofree char *relabel = NULL;
> +    g_autofree char *label = NULL;
> +    g_autofree char *labelskip = NULL;
>      g_autofree xmlNodePtr *list = NULL;
> 
>      if ((n = virXPathNodeSet("./seclabel", ctxt, &list)) < 0)
> @@ -8041,7 +8044,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
>                      goto error;
>                  }
>              }
> -            seclabels[i]->model = model;
> +            seclabels[i]->model = g_steal_pointer(&model);
>          }
> 
>          relabel = virXMLPropString(list[i], "relabel");

Forgot to squash the following diff into this commit:

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 17ba810467..16dea34890 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8017,10 +8017,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
     size_t nseclabels = 0;
     int n;
     size_t i, j;
-    g_autofree char *model = NULL;
-    g_autofree char *relabel = NULL;
-    g_autofree char *label = NULL;
-    g_autofree char *labelskip = NULL;
     g_autofree xmlNodePtr *list = NULL;

     if ((n = virXPathNodeSet("./seclabel", ctxt, &list)) < 0)
@@ -8034,6 +8030,11 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLabelDef ***seclabels_rtn,
         seclabels[i] = g_new0(virSecurityDeviceLabelDef, 1);

     for (i = 0; i < n; i++) {
+        g_autofree char *model = NULL;
+        g_autofree char *relabel = NULL;
+        g_autofree char *label = NULL;
+        g_autofree char *labelskip = NULL;
+
         /* get model associated to this override */
         model = virXMLPropString(list[i], "model");
         if (model) {




[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