Re: [PATCH 08/11] xen_xl.c: Use g_autofree more

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

 



On a Friday in 2022, Michal Privoznik wrote:
There are few places inside src/libxl/xen_xl.c that can benefit
from g_autofree. Let them use automatic memory freeing.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
src/libxl/xen_xl.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)


[...]

@@ -952,13 +951,13 @@ xenParseXLChannel(virConf *conf, virDomainDef *def)
{
    virConfValue *list = virConfGetValue(conf, "channel");
    virDomainChrDef *channel = NULL;
-    char *name = NULL;
-    char *path = NULL;

    if (list && list->type == VIR_CONF_LIST) {
        list = list->list;
        while (list) {
            g_autofree char *type = NULL;
+            g_autofree char *name = NULL;
+            g_autofree char *path = NULL;
            char *key;

            if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
@@ -1003,7 +1002,6 @@ xenParseXLChannel(virConf *conf, virDomainDef *def)

There's a mix of g_auto with manual freeing here:

                } else if (STRPREFIX(key, "name=")) {
                    int len = nextkey ? (nextkey - data) : strlen(data);
                    VIR_FREE(name);
                    name = g_strndup(data, len);
                } else if (STRPREFIX(key, "path=")) {
                    int len = nextkey ? (nextkey - data) : strlen(data);
                    VIR_FREE(path);
                    path = g_strndup(data, len);
                }

I would prefer either altering the code to take the first key into
account instead of the last one by checking:

  else if (!name && STRPREFIX...

similarly how we do in node-based XML parsers, or leaving these two
variables unconverted and leave the refactor for later.

Jano

                channel->source->data.nix.path = g_steal_pointer(&path);
            } else if (STRPREFIX(type, "pty")) {

Attachment: signature.asc
Description: PGP signature


[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