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

Ján Tomko jtomko at redhat.com
Tue Nov 23 14:34:35 UTC 2021


On a Monday in 2021, Peter Krempa wrote:
>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 at redhat.com>
>> ---
>>  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 */

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/20211123/2f68ce5c/attachment-0001.sig>


More information about the libvir-list mailing list