From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [PULL 1/9] block/gluster: Use g_autofree for string in qemu_gluster_parse_json()
Date: Tue, 22 Oct 2024 18:48:55 +0200 [thread overview]
Message-ID: <20241022164903.282174-2-kwolf@redhat.com> (raw)
In-Reply-To: <20241022164903.282174-1-kwolf@redhat.com>
From: Peter Maydell <peter.maydell@linaro.org>
In the loop in qemu_gluster_parse_json() we do:
char *str = NULL;
for(...) {
str = g_strdup_printf(...);
...
if (various errors) {
goto out;
}
...
g_free(str);
str = NULL;
}
return 0;
out:
various cleanups;
g_free(str);
...
return -errno;
Coverity correctly complains that the assignment "str = NULL" at the
end of the loop is unnecessary, because we will either go back to the
top of the loop and overwrite it, or else we will exit the loop and
then exit the function without ever reading str again. The assignment
is there as defensive coding to ensure that str is only non-NULL if
it's a live allocation, so this is intentional.
We can make Coverity happier and simplify the code here by using
g_autofree, since we never need 'str' outside the loop.
Resolves: Coverity CID 1527385
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20241008164708.2966400-2-peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/gluster.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/block/gluster.c b/block/gluster.c
index f03d05251e..e9c038042b 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -514,7 +514,6 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
SocketAddressList **tail;
QDict *backing_options = NULL;
Error *local_err = NULL;
- char *str = NULL;
const char *ptr;
int i, type, num_servers;
@@ -547,7 +546,8 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
tail = &gconf->server;
for (i = 0; i < num_servers; i++) {
- str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.", i);
+ g_autofree char *str = g_strdup_printf(GLUSTER_OPT_SERVER_PATTERN"%d.",
+ i);
qdict_extract_subqdict(options, &backing_options, str);
/* create opts info from runtime_type_opts list */
@@ -658,8 +658,6 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
qobject_unref(backing_options);
backing_options = NULL;
- g_free(str);
- str = NULL;
}
return 0;
@@ -668,7 +666,6 @@ out:
error_propagate(errp, local_err);
qapi_free_SocketAddress(gsconf);
qemu_opts_del(opts);
- g_free(str);
qobject_unref(backing_options);
errno = EINVAL;
return -errno;
--
2.47.0
next prev parent reply other threads:[~2024-10-22 16:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-22 16:48 [PULL 0/9] Block layer patches Kevin Wolf
2024-10-22 16:48 ` Kevin Wolf [this message]
2024-10-22 16:48 ` [PULL 2/9] block/ssh.c: Don't double-check that characters are hex digits Kevin Wolf
2024-10-22 16:48 ` [PULL 3/9] tests/qemu-iotests/211.out: Update to expect MapEntry 'compressed' field Kevin Wolf
2024-10-22 16:48 ` [PULL 4/9] block/vdi.c: Make SECTOR_SIZE constant 64-bits Kevin Wolf
2024-10-22 16:48 ` [PULL 5/9] iotests/backup-discard-source: convert size variable to be int Kevin Wolf
2024-10-22 16:49 ` [PULL 6/9] iotests/backup-discard-source: don't use actual-size Kevin Wolf
2024-10-22 16:49 ` [PULL 7/9] qapi: add qom-path to BLOCK_IO_ERROR event Kevin Wolf
2024-10-22 16:49 ` [PULL 8/9] block-backend: per-device throttling of BLOCK_IO_ERROR reports Kevin Wolf
2024-10-22 16:49 ` [PULL 9/9] raw-format: Fix error message for invalid offset/size Kevin Wolf
2024-10-24 14:21 ` [PULL 0/9] Block layer patches Peter Maydell
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=20241022164903.282174-2-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).