migration: tls: unref creds after used
PATCH 1/1 migration: tls: unref creds after used
We add the reference of creds in migration_tls_get_creds(), but there was no place to unref it. So the OBJECT(creds) will never be freed and result in memory leak.
Unref the creds after creating the tls-channel server/client.
--- migration/tls.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
migration/tls.c +9 -3
@@ -97,7 +97,7 @@ void migration_tls_channel_process_incoming(MigrationState *s, s->parameters.tls_authz, errp);if (!tioc) { -return ; + goto cleanup; }trace_migration_tls_incoming_handshake_start ();
@@ -107,6 +107,9 @@ void migration_tls_channel_process_incoming(MigrationState *s,NULL ,NULL , NULL); + +cleanup: +object_unref (OBJECT (creds)); }
@@ -146,13 +149,13 @@ void migration_tls_channel_connect(MigrationState *s, }if (!hostname) {error_setg (errp,"No hostname available for TLS" ); -return ; + goto cleanup; } tioc =qio_channel_tls_new_client ( ioc, creds, hostname, errp);if (!tioc) { -return ; + goto cleanup; }trace_migration_tls_outgoing_handshake_start (hostname);
@@ -162,4 +165,7 @@ void migration_tls_channel_connect(MigrationState *s, s,NULL , NULL); + +cleanup: +object_unref (OBJECT (creds)); }
Signature · 1 line
2.19.1
Quoted 51 lines · Zhenyu Ye
We add the reference of creds in
migration_tls_get_creds(), but there was no place to unref it. So the OBJECT(creds) will never be freed and result in memory leak.Unref the creds after creating the tls-channel server/client.
Signed-off-by Zhenyu Ye <[email protected]>--- migration/tls.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)migration/tls.c +6
-3@@ -97,7 +97,7 @@ void migration_tls_channel_process_incoming(MigrationState *s, s->parameters.tls_authz, errp);if (!tioc) { -return ; + goto cleanup; }trace_migration_tls_incoming_handshake_start ();@@ -107,6 +107,9 @@ void migration_tls_channel_process_incoming(MigrationState *s,NULL ,NULL , NULL); + +cleanup: +object_unref (OBJECT (creds)); }@@ -146,13 +149,13 @@ void migration_tls_channel_connect(MigrationState *s, }if (!hostname) {error_setg (errp,"No hostname available for TLS" ); -return ; + goto cleanup; } tioc =qio_channel_tls_new_client ( ioc, creds, hostname, errp);if (!tioc) { -return ; + goto cleanup; }trace_migration_tls_outgoing_handshake_start (hostname);
migration/tls.c void migration_tls_channel_connect(MigrationState *s, · line 171
Quoted 7 lines
migration/tls.c +3
-0@@ -162,4 +165,7 @@ void migration_tls_channel_connect(MigrationState *s, s,NULL , NULL); + +cleanup: +object_unref (OBJECT (creds)); }
Simpler to just change migration_tls_get_creds() to remove the object_ref() call, since we're fine to use the borrowed reference in these methods.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 8 lines · Daniel P. Berrangé
Quoted 7 lines · Zhenyu Ye
We add the reference of creds in
migration_tls_get_creds(), but there was no place to unref it. So the OBJECT(creds) will never be freed and result in memory leak.Unref the creds after creating the tls-channel server/client.
...
Quoted 9 lines
migration/tls.c void migration_tls_channel_process_incoming(MigrationState *s, · line 113
Quoted 4 lines
migration/tls.c +3
-0+ +cleanup: +object_unref (OBJECT (creds)); }Simpler to just change
migration_tls_get_creds()to remove theobject_ref()call, since we're fine to use the borrowed reference in these methods.
Thanks for your review. I have sent a new series since the current title "unref creds after used" is no longer appropriate:
https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
Zhenyu