On Mittwoch, 26. Januar 2022 18:11:36 CET Greg Kurz wrote:
> The template pointer in virtio_9p_create_local_test_dir() is leaked.
> Add the g_autofree annotation to fix that. While here, convert the
> rest of the virtio 9p test code to using g_autofree or g_autoptr
> where possible, since this is the preferred approach to avoid potential
> leaks in the future.
> 
> Based-on:
> <f6602123c6f7d0d593466231b04fba087817abbd.1642879848.git.qemu_oss@crudebyte
> .com> Signed-off-by: Greg Kurz <gr...@kaod.org>
> ---
>  tests/qtest/libqos/virtio-9p.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)

I fear there is something wrong with this patch:

# Start of local tests
# starting QEMU: exec x86_64-softmmu/qemu-system-x86_64 -qtest 
unix:/tmp/qtest-4234.sock -qtest-log /dev/null -chardev 
socket,path=/tmp/qtest-4234.qmp,id=char0 -mon chardev=char0,mode=control 
-display none -M pc  -fsdev local,id=fsdev0,path='',security_model=mapped-xattr 
-device virtio-9p-pci,fsdev=fsdev0,addr=04.0,mount_tag=qtest -accel qtest
qemu-system-x86_64: -device 
virtio-9p-pci,fsdev=fsdev0,addr=04.0,mount_tag=qtest: cannot initialize fsdev 
'fsdev0': failed to open '': No such file or directory
Broken pipe
Aborted

> 
> diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c
> index ef96ef006adc..0a0d0d16709b 100644
> --- a/tests/qtest/libqos/virtio-9p.c
> +++ b/tests/qtest/libqos/virtio-9p.c
> @@ -40,14 +40,13 @@ static char *concat_path(const char* a, const char* b)
>  void virtio_9p_create_local_test_dir(void)
>  {
>      struct stat st;
> -    char *pwd = g_get_current_dir();
> -    char *template = concat_path(pwd, "qtest-9p-local-XXXXXX");
> +    g_autofree char *pwd = g_get_current_dir();
> +    g_autofree char *template = concat_path(pwd, "qtest-9p-local-XXXXXX");
> 
>      local_test_path = mkdtemp(template);
>      if (!local_test_path) {
>          g_test_message("mkdtemp('%s') failed: %s", template,
> strerror(errno)); }
> -    g_free(pwd);
> 
>      g_assert(local_test_path != NULL);
> 
> @@ -60,12 +59,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);
>  }
> 
>  char *virtio_9p_test_path(const char *path)
> @@ -209,8 +207,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);
> @@ -220,9 +218,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)



Reply via email to