summaryrefslogtreecommitdiffstats
path: root/tests/qtest/libqos
diff options
context:
space:
mode:
authorGreg Kurz2022-02-01 16:15:08 +0100
committerChristian Schoenebeck2022-02-17 16:57:58 +0100
commit494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4 (patch)
treed9c4100e820695d44e721c5d87330b1dbc303200 /tests/qtest/libqos
parenttests/9pfs: Fix leak of local_test_path (diff)
downloadqemu-494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4.tar.gz
qemu-494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4.tar.xz
qemu-494fbbd3ed46a14ef0924651c058b9b0dcb4a7b4.zip
tests/9pfs: Use g_autofree and g_autoptr where possible
It is recommended to use g_autofree or g_autoptr as it reduces the odds of introducing memory leaks in future changes. Signed-off-by: Greg Kurz <groug@kaod.org> Message-Id: <20220201151508.190035-3-groug@kaod.org> Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Diffstat (limited to 'tests/qtest/libqos')
-rw-r--r--tests/qtest/libqos/virtio-9p.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
index 5d18e5eae5..f51f0635cc 100644
--- a/tests/qtest/libqos/virtio-9p.c
+++ b/tests/qtest/libqos/virtio-9p.c
@@ -41,7 +41,7 @@ void virtio_9p_create_local_test_dir(void)
{
g_assert(local_test_path == NULL);
struct stat st;
- char *pwd = g_get_current_dir();
+ g_autofree char *pwd = g_get_current_dir();
/*
* template gets cached into local_test_path and freed in
* virtio_9p_remove_local_test_dir().
@@ -52,7 +52,6 @@ void virtio_9p_create_local_test_dir(void)
if (!local_test_path) {
g_test_message("mkdtemp('%s') failed: %s", template, strerror(errno));
}
- g_free(pwd);
g_assert(local_test_path != NULL);
@@ -65,12 +64,11 @@ void virtio_9p_create_local_test_dir(void)
void virtio_9p_remove_local_test_dir(void)
{
g_assert(local_test_path != NULL);
- char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path);
+ g_autofree char *cmd = g_strdup_printf("rm -fr '%s'\n", local_test_path);
int res = system(cmd);
if (res < 0) {
/* ignore error, dummy check to prevent compiler error */
}
- g_free(cmd);
g_free(local_test_path);
local_test_path = NULL;
}
@@ -216,8 +214,8 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc,
static void regex_replace(GString *haystack, const char *pattern,
const char *replace_fmt, ...)
{
- GRegex *regex;
- char *replace, *s;
+ g_autoptr(GRegex) regex = NULL;
+ g_autofree char *replace = NULL, *s = NULL;
va_list argp;
va_start(argp, replace_fmt);
@@ -227,9 +225,6 @@ static void regex_replace(GString *haystack, const char *pattern,
regex = g_regex_new(pattern, 0, 0, NULL);
s = g_regex_replace(regex, haystack->str, -1, 0, replace, 0, NULL);
g_string_assign(haystack, s);
- g_free(s);
- g_regex_unref(regex);
- g_free(replace);
}
void virtio_9p_assign_local_driver(GString *cmd_line, const char *args)