public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Prasad Pandit <ppandit@redhat.com>
Cc: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
	Peter Xu <peterx@redhat.com>, Laurent Vivier <lvivier@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 1/8] tests/qtest/migration: Fix leak of migration tests data
Date: Wed, 11 Mar 2026 09:57:55 -0300	[thread overview]
Message-ID: <87ikb2zfos.fsf@suse.de> (raw)
In-Reply-To: <CAE8KmOx5XbY1m40gGb5_kDOwt5D_YMT1YDp1JFugK-6NMRW3YA@mail.gmail.com>

Prasad Pandit <ppandit@redhat.com> writes:

> On Tue, 10 Mar 2026 at 19:26, Fabiano Rosas <farosas@suse.de> wrote:
>> When the migration-test is invoked with the '-p' flag (to run a single
>> test), the glib code won't call the destroy function for the
>> not-executed tests, causing the MigrationTest wrapper data to leak.
>
> * With -p, only test data for that test should be loaded, right?
> Freeing the data for non-executed tests does not seem right.
>

Hm, I don't know what you mean by loaded. Glib will call only the
specific test, passing the data that was registered along with that
test. That registration is done beforehand with the glib_add_data_func
functions. We need to allocate that somehow. If we allocated it, we must
free it.

Ideally, glib would provide a hook for setup and another one for
teardown, which would work like (I think) you expect. But it doesn't do
that. The "destroy" hook is semantically "undo what was done in the
test", not free resources allocated outside of glib.

Some simpler tests can avoid dynamically allocation, but migration-test
is a bit more complex, so I don't see a way to do that at the moment.

>> This doesn't affect make check, but affects debugging use-cases where
>> having a leak pop up in ASAN output is extra annoying.
>>
>> Fix by adding the tests data to a list and freeing them all at the end
>> of migration-test execution. Any tests actually dispatched by glib
>> will have the destroy function called as usual.
>>
>> Note that migration_test_add_suffix() is altered to call
>> migration_test_add() so that there's only one place adding the data to
>> the list.
>>
>> Performance is not an issue at the moment, we have < 100 tests.
>>
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>  tests/qtest/migration/framework.c      |  2 ++
>>  tests/qtest/migration/migration-util.c | 19 ++++++++++++++-----
>>  tests/qtest/migration/migration-util.h |  2 +-
>>  3 files changed, 17 insertions(+), 6 deletions(-)
>>
>> diff --git a/tests/qtest/migration/framework.c b/tests/qtest/migration/framework.c
>> index 0bfc241914..b9371372de 100644
>> --- a/tests/qtest/migration/framework.c
>> +++ b/tests/qtest/migration/framework.c
>> @@ -1162,5 +1162,7 @@ int migration_env_clean(MigrationTestEnv *env)
>>      }
>>      g_free(tmpfs);
>>
>> +    migration_tests_free();
>> +
>>      return ret;
>>  }
>> diff --git a/tests/qtest/migration/migration-util.c b/tests/qtest/migration/migration-util.c
>> index c2462306a1..2648ad7f61 100644
>> --- a/tests/qtest/migration/migration-util.c
>> +++ b/tests/qtest/migration/migration-util.c
>> @@ -38,6 +38,7 @@
>>  #include "linux/kvm.h"
>>  #endif
>>
>> +GQueue *tests;
>>
>>  static char *SocketAddress_to_str(SocketAddress *addr)
>>  {
>> @@ -243,6 +244,8 @@ static void migration_test_destroy(gpointer data)
>>  {
>>      MigrationTest *test = (MigrationTest *)data;
>>
>> +    g_queue_remove(tests, test);
>> +
>>      g_free(test->data);
>>      g_free(test->name);
>>      g_free(test);
>> @@ -268,21 +271,27 @@ void migration_test_add(const char *path,
>>
>>      qtest_add_data_func_full(path, test, migration_test_wrapper,
>>                               migration_test_destroy);
>> +    if (!tests) {
>> +        tests = g_queue_new();
>> +    }
>> +    g_queue_push_tail(tests, test);
>>  }
>>
>>  void migration_test_add_suffix(const char *path, const char *suffix,
>>                                 void (*fn)(char *name, MigrateCommon *args))
>>  {
>> -    MigrationTest *test = g_new0(MigrationTest, 1);
>> +    g_autofree char *name = NULL;
>>
>>      g_assert(g_str_has_suffix(path, "/"));
>>      g_assert(!g_str_has_prefix(suffix, "/"));
>>
>> -    test->func = fn;
>> -    test->name = g_strconcat(path, suffix, NULL);
>> +    name = g_strconcat(path, suffix, NULL);
>> +    migration_test_add(name, fn);
>> +}
>>
>> -    qtest_add_data_func_full(test->name, test, migration_test_wrapper,
>> -                             migration_test_destroy);
>> +void migration_tests_free(void)
>> +{
>> +    g_queue_free_full(tests, migration_test_destroy);
>>  }
>>
>>  #ifdef O_DIRECT
>> diff --git a/tests/qtest/migration/migration-util.h b/tests/qtest/migration/migration-util.h
>> index e73d69bab0..694773e594 100644
>> --- a/tests/qtest/migration/migration-util.h
>> +++ b/tests/qtest/migration/migration-util.h
>> @@ -59,5 +59,5 @@ void migration_test_add_suffix(const char *path, const char *suffix,
>>                                 void (*fn)(char *name, MigrateCommon *args));
>>  char *migrate_get_connect_uri(QTestState *who);
>>  void migrate_set_ports(QTestState *to, QList *channel_list);
>> -
>> +void migration_tests_free(void);
>>  #endif /* MIGRATION_UTIL_H */
>> --
>
> * Change looks okay. Still I think there could be a way to load only
> the data required for the specific test.
> Reviewed-by: Prasad Pandit <pjp@fedoraproject.org>
>
> Thank you.
> ---
>   - Prasad


      reply	other threads:[~2026-03-11 12:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-10 13:55 [PATCH 1/8] tests/qtest/migration: Fix leak of migration tests data Fabiano Rosas
2026-03-10 13:55 ` [PATCH 2/8] tests/qtest/migration: Change validate_uuid test to not trigger exit(1) Fabiano Rosas
2026-03-10 19:59   ` Peter Xu
2026-03-11 10:34   ` Prasad Pandit
2026-03-10 13:55 ` [PATCH 3/8] tests/qtest/migration: Fix misuse of listen_uri Fabiano Rosas
2026-03-10 15:48   ` Lukas Straub
2026-03-10 13:55 ` [PATCH 4/8] tests/qtest/migration: Stop invoking migrate_incoming from hooks Fabiano Rosas
2026-03-10 15:47   ` Lukas Straub
2026-03-10 13:55 ` [PATCH 5/8] tests/qtest/migration: Force exit-on-error=false when appropriate Fabiano Rosas
2026-03-10 20:46   ` Peter Xu
2026-03-10 21:14     ` Fabiano Rosas
2026-03-11 10:36       ` Prasad Pandit
2026-03-11 15:40       ` Peter Xu
2026-03-10 13:55 ` [PATCH 6/8] io: Fix TLS bye task leak Fabiano Rosas
2026-03-10 14:29   ` Daniel P. Berrangé
2026-03-10 13:55 ` [PATCH 7/8] tests/qtest/migration: Fix leak in CPR exec test Fabiano Rosas
2026-03-10 20:46   ` Peter Xu
2026-03-11  9:56   ` Prasad Pandit
2026-03-10 13:55 ` [PATCH 8/8] migration/multifd: Fix leaks of TLS error objects Fabiano Rosas
2026-03-10 20:49   ` Peter Xu
2026-03-11  9:32   ` Prasad Pandit
2026-03-10 19:47 ` [PATCH 1/8] tests/qtest/migration: Fix leak of migration tests data Peter Xu
2026-03-11 11:56 ` Prasad Pandit
2026-03-11 12:57   ` Fabiano Rosas [this message]

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=87ikb2zfos.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=ppandit@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox