migration: fix QIOChannelFile leak on error in file_connect_outgoing
PATCH 1/1 migration: fix QIOChannelFile leak on error in file_connect_outgoing
Commit 03a680c978 changed g_autoptr(QIOChannelFile) to a plain pointer but failed to restore the necessary object_unref() calls on error paths. Previously, these were handled implicitly by the g_autoptr cleanup mechanism.
Two error paths currently leak the QIOChannelFile object and its underlying file descriptor:
1. When ftruncate() fails (e.g., on character or block devices).
2. When qio_channel_io_seek() fails after the channel is created.
In environments that retry migration automatically (e.g., libvirt), these FDs accumulate until QEMU hits RLIMIT_NOFILE and fails with EMFILE (Too many open files).
Add the missing object_unref() calls to both error paths to ensure resources are properly released.
--- migration/file.c | 2 ++ tests/qtest/migration/file-tests.c | 48 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
migration/file.c +2 -0
@@ -112,6 +112,7 @@ QIOChannel *file_connect_outgoing(MigrationState *s,error_setg_errno (errp, errno,"failed to truncate migration file to offset %" PRIx64, offset); +object_unref (OBJECT (fioc)); goto out; }
@@ -119,6 +120,7 @@ QIOChannel *file_connect_outgoing(MigrationState *s, ioc =QIO_CHANNEL (fioc);if (offset &&qio_channel_io_seek (ioc, offset,SEEK_SET , errp) <0 ) { +object_unref (OBJECT (fioc)); ioc =NULL ; goto out; }
tests/qtest/migration/file-tests.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 11 lines · Trieu Huynh
Commit
03a680c978changedg_autoptr(QIOChannelFile)to a plain pointer but failed to restore the necessaryobject_unref()calls on error paths. Previously, these were handled implicitly by theg_autoptrcleanup mechanism.Two error paths currently leak the QIOChannelFile object and its underlying file descriptor:
1. When
ftruncate()fails (e.g., on character or block devices).
2. Whenqio_channel_io_seek()fails after the channel is created.
Quoted 8 lines
In environments that retry migration automatically (e.g., libvirt), these FDs accumulate until QEMU hits
RLIMIT_NOFILEand fails with EMFILE (Too many open files).Add the missing
object_unref()calls to both error paths to ensure resources are properly released.Signed-off-by Trieu Huynh <[email protected]>
Good catch.
I'm just curious, how did you find it?
Signature · 1 line
Peter Xu
Quoted 19 lines · Peter Xu
Quoted 18 lines · Trieu Huynh
Commit
03a680c978changedg_autoptr(QIOChannelFile)to a plain pointer but failed to restore the necessaryobject_unref()calls on error paths. Previously, these were handled implicitly by theg_autoptrcleanup mechanism.Two error paths currently leak the QIOChannelFile object and its underlying file descriptor:
1. When
ftruncate()fails (e.g., on character or block devices).
2. Whenqio_channel_io_seek()fails after the channel is created.In environments that retry migration automatically (e.g., libvirt), these FDs accumulate until QEMU hits
RLIMIT_NOFILEand fails with EMFILE (Too many open files).Add the missing
object_unref()calls to both error paths to ensure resources are properly released.
Quoted 8 lines
Quoted 1 line
Signed-off-by Trieu Huynh <[email protected]>Good catch.
Reviewed-by Peter Xu <[email protected]>I'm just curious, how did you find it?
Thanks, just by change, while researching the codebase and blame some locs :)
Quoted 3 lines
Signature · 1 line
Peter Xu