migration: fix small leaks
PATCH 1/1 migration: fix small leaks
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)
--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
migration/migration.c +10 -0
@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);
@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize, };static void register_migration_types (void )
Signature · 1 line
2.14.0.rc0.1.g40ca67566
Quoted 16 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)
Quoted 1 line
Signed-off-by Marc-André Lureau <[email protected]>
Thanks,
Signature · 1 line
Peter Xu
Quoted 16 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)
Quoted 1 line
Signed-off-by Marc-André Lureau <[email protected]>
Quoted 16 lines · * Marc-André Lureau ([email protected]) wrote:
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)
Quoted 1 line
Signed-off-by Marc-André Lureau <[email protected]>
Queued for migration
Quoted 35 lines
--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize, };static void register_migration_types (void )Signature · 1 line
2.14.0.rc0.1.g40ca67566
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Hi all!
Hmm, looks like leak is not fixed here: I've checked it while running iotest 181, that migration_instance_finalize is not called.
If I understand correct, to call it we need unref current_migration object somewhere.
Or, may be I'm missing something..
Quoted 49 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)Signed-off-by Marc-André Lureau <[email protected]>--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize, };static void register_migration_types (void )
Signature · 2 lines
Best regards, Vladimir
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Hi all!
Hmm, looks like leak is not fixed here: I've checked it while running iotest 181, that
migration_instance_finalizeis not called.If I understand correct, to call it we need unref
current_migrationobject somewhere.Or, may be I'm missing something..
I think you are right.
It does not matter much though since we don't dynamically allocate migration object (there is only one and it lives forever). Do you want to post a patch? I guess the safest place to unref it is at the end of main() to make sure no one will be using it any more.
(Hmm, the incoming migration state is still static)
Thanks,
Quoted 56 lines
Quoted 47 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)Signed-off-by Marc-André Lureau <[email protected]>--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize, };static void register_migration_types (void )Signature · 2 lines
Best regards, Vladimir
Signature · 1 line
Peter Xu
Quoted 13 lines · Peter Xu
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Hi all!
Hmm, looks like leak is not fixed here: I've checked it while running iotest 181, that
migration_instance_finalizeis not called.If I understand correct, to call it we need unref
current_migrationobject somewhere.Or, may be I'm missing something..
I think you are right.
Quoted 8 lines
It does not matter much though since we don't dynamically allocate migration object (there is only one and it lives forever). Do you want to post a patch? I guess the safest place to unref it is at the end of
main()to make sure no one will be using it any more.(Hmm, the incoming migration state is still static)
Thanks,
Ok, I'll send a patch.
Quoted 55 lines
Quoted 55 lines
Quoted 47 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)Signed-off-by Marc-André Lureau <[email protected]>--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize, };static void register_migration_types (void )Signature · 2 lines
Best regards, Vladimir
Signature · 2 lines
Best regards, Vladimir
Quoted 19 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 18 lines · Peter Xu
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Hi all!
Hmm, looks like leak is not fixed here: I've checked it while running iotest 181, that
migration_instance_finalizeis not called.If I understand correct, to call it we need unref
current_migrationobject somewhere.Or, may be I'm missing something..
I think you are right.
It does not matter much though since we don't dynamically allocate migration object (there is only one and it lives forever). Do you want to post a patch? I guess the safest place to unref it is at the end of
main()to make sure no one will be using it any more.
Quoted 5 lines
Quoted 3 lines
(Hmm, the incoming migration state is still static)
Thanks,
Ok, I'll send a patch.
Be very very careful that it doesn't crash in cases like quit in the main thread while a migration is still running.
I have no problem with this object living forever and letting it just die with exit().
Dave
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 45 lines · Marc-André Lureau
Spotted thanks to valgrind and tests/device-introspect-test:
==11711== 1 bytes in 1 blocks are definitely lost in loss record 6 of 14,537
==11711== at 0x4C2EB6B: malloc (vg_replace_malloc.c:299) ==11711== by 0x1E0CDBD8: g_malloc (gmem.c:94) ==11711== by 0x1E0E696E: g_strdup (gstrfuncs.c:363) ==11711== by 0x695693: migration_instance_init (migration.c:2226) ==11711== by 0x717C4B: object_init_with_type (object.c:344) ==11711== by 0x717E80: object_initialize_with_type (object.c:375) ==11711== by 0x7182EB: object_new_with_type (object.c:483) ==11711== by 0x718328: object_new (object.c:493) ==11711== by 0x4B8A29: qmp_device_list_properties (qmp.c:542) ==11711== by 0x4A9561: qmp_marshal_device_list_properties (qmp-marshal.c:1425) ==11711== by 0x819D4A: do_qmp_dispatch (qmp-dispatch.c:104) ==11711== by 0x819E82: qmp_dispatch (qmp-dispatch.c:131)Signed-off-by Marc-André Lureau <[email protected]>--- migration/migration.c | 10 ++++++++++ 1 file changed, 10 insertions(+)migration/migration.c +10
-0@@ -2214,6 +2214,15 @@ static void migration_class_init(ObjectClass *klass, void *data) dc->props = migration_properties; } +static void migration_instance_finalize (Object *obj) +{ +MigrationState *ms =MIGRATION_OBJ (obj); +MigrationParameters *params = &ms->parameters; + +g_free (params->tls_hostname); +g_free (params->tls_creds); +} +static void migration_instance_init (Object *obj) {MigrationState *ms =MIGRATION_OBJ (obj);@@ -2282,6 +2291,7 @@ static const TypeInfo migration_type = { .class_size = sizeof(MigrationClass), .instance_size = sizeof(MigrationState), .instance_init = migration_instance_init, + .instance_finalize = migration_instance_finalize,
Quoted 14 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
migration/migration.c +0
-0};static void register_migration_types (void )Signature · 2 lines
Best regards, VladimirSignature · 2 lines
Best regards, Vladimir
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 20 lines · Dr. David Alan Gilbert
Quoted 19 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:
Quoted 18 lines · Peter Xu
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Hi all!
Hmm, looks like leak is not fixed here: I've checked it while running iotest 181, that
migration_instance_finalizeis not called.If I understand correct, to call it we need unref
current_migrationobject somewhere.Or, may be I'm missing something..
I think you are right.
It does not matter much though since we don't dynamically allocate migration object (there is only one and it lives forever). Do you want to post a patch? I guess the safest place to unref it is at the end of
main()to make sure no one will be using it any more.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
(Hmm, the incoming migration state is still static)
Thanks,
Ok, I'll send a patch.
Be very very careful that it doesn't crash in cases like quit in the main thread while a migration is still running.
Agree.
Quoted 3 lines
I have no problem with this object living forever and letting it just die with
exit().
Yes. But if better, I am thinking whether we should always make sure migration is completed/failed/cancelled before that point. If we quit QEMU with a working migration stream, logically we should stop it before leaving, as part of QEMU's cleanup path.
Signature · 1 line
Peter Xu