All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: qemu-devel@nongnu.org
Cc: "Markus Armbruster" <armbru@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>
Subject: [PATCH v2 01/11] qemu-option: Use g_autofree when calling get_opt_name_value()
Date: Wed, 30 Sep 2026 19:10:55 -0300	[thread overview]
Message-ID: <20260930221105.2262063-2-farosas@suse.de> (raw)
In-Reply-To: <20260930221105.2262063-1-farosas@suse.de>

The get_opt_name_value function takes two pointer arguments that must
be freed by the callers when not used. This is a good situation to use
g_autofree. Steal the pointers that need to be passed forward.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 util/qemu-option.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 9fbf425f86..557d5d929c 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -813,27 +813,24 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,
                           const char *firstname,
                           bool warn_on_flag, bool *help_wanted, Error **errp)
 {
-    char *option, *value;
     const char *p;
     QemuOpt *opt;
 
     for (p = params; *p;) {
+        g_autofree char *option = NULL;
+        g_autofree char *value = NULL;
+
         p = get_opt_name_value(p, firstname, warn_on_flag, help_wanted, &option, &value);
         if (help_wanted && *help_wanted) {
-            g_free(option);
-            g_free(value);
             return false;
         }
         firstname = NULL;
 
         if (!strcmp(option, "id")) {
-            g_free(option);
-            g_free(value);
             continue;
         }
 
-        opt = opt_create(opts, option, value);
-        g_free(option);
+        opt = opt_create(opts, option, g_steal_pointer(&value));
         if (!opt_validate(opt, errp)) {
             qemu_opt_del(opt);
             return false;
@@ -846,16 +843,15 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,
 static char *opts_parse_id(const char *params)
 {
     const char *p;
-    char *name, *value;
 
     for (p = params; *p;) {
+        g_autofree char *name = NULL;
+        g_autofree char *value = NULL;
+
         p = get_opt_name_value(p, NULL, false, NULL, &name, &value);
         if (!strcmp(name, "id")) {
-            g_free(name);
-            return value;
+            return g_steal_pointer(&value);
         }
-        g_free(name);
-        g_free(value);
     }
 
     return NULL;
@@ -864,13 +860,13 @@ static char *opts_parse_id(const char *params)
 bool has_help_option(const char *params)
 {
     const char *p;
-    char *name, *value;
     bool ret = false;
 
     for (p = params; *p;) {
+        g_autofree char *name = NULL;
+        g_autofree char *value = NULL;
+
         p = get_opt_name_value(p, NULL, false, &ret, &name, &value);
-        g_free(name);
-        g_free(value);
         if (ret) {
             return true;
         }
-- 
2.53.0



  reply	other threads:[~2026-09-30 22:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 22:10 [PATCH v2 00/11] qemu-options: Spring cleanup Fabiano Rosas
2026-09-30 22:10 ` Fabiano Rosas [this message]
2026-10-01  9:42   ` [PATCH v2 01/11] qemu-option: Use g_autofree when calling get_opt_name_value() marcandre.lureau
2026-09-30 22:10 ` [PATCH v2 02/11] tests/unit/test-qemu-opts: Validate help=foo options Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-09-30 22:10 ` [PATCH v2 03/11] qemu-option: Remove short form options support Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-10-07  7:08   ` Markus Armbruster
2026-10-07 12:43     ` Fabiano Rosas
2026-10-08  4:42       ` Markus Armbruster
2026-10-10  0:04         ` Fabiano Rosas
2026-10-07  8:16   ` Markus Armbruster
2026-09-30 22:10 ` [PATCH v2 04/11] qemu-option: Fix 'help' parameter parsing Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-10-01 15:43     ` Fabiano Rosas
2026-09-30 22:10 ` [PATCH v2 05/11] qemu-option: Add qemu_opts_parse_list Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-09-30 22:11 ` [PATCH v2 06/11] qemu-option: Change qemu_parse_opts() to take the group name Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-09-30 22:11 ` [PATCH v2 07/11] qemu-option: Add qemu_opts_parse_list_noisily Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-10-07 12:54   ` Eric Blake
2026-09-30 22:11 ` [PATCH v2 08/11] qemu-option: Use qemu_opts_parse_list_noisily where appropriate Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-09-30 22:11 ` [PATCH v2 09/11] qemu-option: Change qemu_opts_parse_noisily() to take the group Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-10-07 12:54   ` Eric Blake
2026-09-30 22:11 ` [PATCH v2 10/11] qemu-option: Check for NULL list at qemu_opts_parse() Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau
2026-09-30 22:11 ` [PATCH v2 11/11] qemu-option: Remove a few instances of noisily parsing Fabiano Rosas
2026-10-01  9:42   ` marcandre.lureau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930221105.2262063-2-farosas@suse.de \
    --to=farosas@suse.de \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.