From d7e2bca9b7a166e6529e766e6755d11bcd321290 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 22 Mar 2021 18:06:45 +0100 Subject: [PATCH] virshParseEventStr: Use g_strsplit and automatic memory freeing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/virsh-domain.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index a778421b66..86de4255fa 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9342,24 +9342,21 @@ virshParseEventStr(const char *event, int *nparams, int *maxparams) { - char **tok = NULL; - size_t i, ntok; - int ret = -1; + g_auto(GStrv) tok = NULL; + GStrv next; - if (!(tok = virStringSplitCount(event, ",", 0, &ntok))) + if (!(tok = g_strsplit(event, ",", 0))) return -1; - for (i = 0; i < ntok; i++) { - if ((*tok[i] != '\0') && - virTypedParamsAddBoolean(params, nparams, - maxparams, tok[i], state) < 0) - goto cleanup; + for (next = tok; *next; next++) { + if (*next[0] == '\0') + continue; + + if (virTypedParamsAddBoolean(params, nparams, maxparams, *next, state) < 0) + return -1; } - ret = 0; - cleanup: - g_strfreev(tok); - return ret; + return 0; } static void