qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, david@redhat.com, zhukeqian1@huawei.com,
	maozhongyi@cmss.chinamobile.com, marcandre.lureau@redhat.com,
	pannengyuan@huawei.com, f4bug@amsat.org, wei.w.wang@intel.com,
	yi.y.sun@intel.com, quintela@redhat.com
Subject: [PULL 11/12] migration/multifd: fix memleaks in multifd_new_send_channel_async
Date: Thu,  7 May 2020 18:02:10 +0100	[thread overview]
Message-ID: <20200507170211.238283-12-dgilbert@redhat.com> (raw)
In-Reply-To: <20200507170211.238283-1-dgilbert@redhat.com>

From: Pan Nengyuan <pannengyuan@huawei.com>

When error happen in multifd_new_send_channel_async, 'sioc' will not be used
to create the multifd_send_thread. Let's free it to avoid a memleak. And also
do error_free after migrate_set_error() to avoid another leak in the same place.

The leak stack:
Direct leak of 2880 byte(s) in 8 object(s) allocated from:
    #0 0x7f20b5118ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8)
    #1 0x7f20b44df1d5 in g_malloc (/lib64/libglib-2.0.so.0+0x531d5)
    #2 0x564133bce18b in object_new_with_type /mnt/sdb/backup/qemu/qom/object.c:683
    #3 0x564133eea950 in qio_channel_socket_new /mnt/sdb/backup/qemu/io/channel-socket.c:56
    #4 0x5641339cfe4f in socket_send_channel_create /mnt/sdb/backup/qemu/migration/socket.c:37
    #5 0x564133a10328 in multifd_save_setup /mnt/sdb/backup/qemu/migration/multifd.c:772
    #6 0x5641339cebed in migrate_fd_connect /mnt/sdb/backup/qemu/migration/migration.c:3530
    #7 0x5641339d15e4 in migration_channel_connect /mnt/sdb/backup/qemu/migration/channel.c:92
    #8 0x5641339cf5b7 in socket_outgoing_migration /mnt/sdb/backup/qemu/migration/socket.c:108

Direct leak of 384 byte(s) in 8 object(s) allocated from:
    #0 0x7f20b5118cf0 in calloc (/lib64/libasan.so.5+0xefcf0)
    #1 0x7f20b44df22d in g_malloc0 (/lib64/libglib-2.0.so.0+0x5322d)
    #2 0x56413406fc17 in error_setv /mnt/sdb/backup/qemu/util/error.c:61
    #3 0x564134070464 in error_setg_errno_internal /mnt/sdb/backup/qemu/util/error.c:109
    #4 0x5641340851be in inet_connect_addr /mnt/sdb/backup/qemu/util/qemu-sockets.c:379
    #5 0x5641340851be in inet_connect_saddr /mnt/sdb/backup/qemu/util/qemu-sockets.c:458
    #6 0x5641340870ab in socket_connect /mnt/sdb/backup/qemu/util/qemu-sockets.c:1105
    #7 0x564133eeaabf in qio_channel_socket_connect_sync /mnt/sdb/backup/qemu/io/channel-socket.c:145
    #8 0x564133eeabf5 in qio_channel_socket_connect_worker /mnt/sdb/backup/qemu/io/channel-socket.c:168

Indirect leak of 360 byte(s) in 8 object(s) allocated from:
    #0 0x7f20b5118ae8 in __interceptor_malloc (/lib64/libasan.so.5+0xefae8)
    #1 0x7f20af901817 in __GI___vasprintf_chk (/lib64/libc.so.6+0x10d817)
    #2 0x7f20b451fa6c in g_vasprintf (/lib64/libglib-2.0.so.0+0x93a6c)
    #3 0x7f20b44f8cd0 in g_strdup_vprintf (/lib64/libglib-2.0.so.0+0x6ccd0)
    #4 0x7f20b44f8d8c in g_strdup_printf (/lib64/libglib-2.0.so.0+0x6cd8c)
    #5 0x56413406fc86 in error_setv /mnt/sdb/backup/qemu/util/error.c:65
    #6 0x564134070464 in error_setg_errno_internal /mnt/sdb/backup/qemu/util/error.c:109
    #7 0x5641340851be in inet_connect_addr /mnt/sdb/backup/qemu/util/qemu-sockets.c:379
    #8 0x5641340851be in inet_connect_saddr /mnt/sdb/backup/qemu/util/qemu-sockets.c:458
    #9 0x5641340870ab in socket_connect /mnt/sdb/backup/qemu/util/qemu-sockets.c:1105
    #10 0x564133eeaabf in qio_channel_socket_connect_sync /mnt/sdb/backup/qemu/io/channel-socket.c:145
    #11 0x564133eeabf5 in qio_channel_socket_connect_worker /mnt/sdb/backup/qemu/io/channel-socket.c:168

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Pan Nengyuan <pannengyuan@huawei.com>
Message-Id: <20200506095416.26099-2-pannengyuan@huawei.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 migration/multifd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/migration/multifd.c b/migration/multifd.c
index 9123c111a3..e3efd33a0d 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -727,6 +727,8 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque)
          * its status.
          */
         p->quit = true;
+        object_unref(OBJECT(sioc));
+        error_free(local_err);
     } else {
         p->c = QIO_CHANNEL(sioc);
         qio_channel_set_delay(p->c, false);
-- 
2.26.2



  parent reply	other threads:[~2020-05-07 17:09 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 17:01 [PULL 00/12] migration queue Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 01/12] migration: fix bad indentation in error_report() Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 02/12] migration/migration: improve error reporting for migrate parameters Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 03/12] monitor/hmp-cmds: add hmp_handle_error() for hmp_migrate_set_speed() Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 04/12] migration: move the units of migrate parameters from milliseconds to ms Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 05/12] docs/devel/migration: start a debugging section Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 06/12] migration/colo: Add missing error-propagation code Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 07/12] migration/throttle: Add cpu-throttle-tailslow migration parameter Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 08/12] migration/ram: Consolidate variable reset after placement in ram_load_postcopy() Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 09/12] migration/rdma: fix a memleak on error path in rdma_start_incoming_migration Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` [PULL 10/12] migration/xbzrle: add encoding rate Dr. David Alan Gilbert (git)
2020-05-07 17:02 ` Dr. David Alan Gilbert (git) [this message]
2020-05-07 17:02 ` [PULL 12/12] migration/multifd: Do error_free after migrate_set_error to avoid memleaks Dr. David Alan Gilbert (git)
2020-05-07 18:49 ` [PULL 00/12] migration queue Peter Maydell

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=20200507170211.238283-12-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=david@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=maozhongyi@cmss.chinamobile.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pannengyuan@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=wei.w.wang@intel.com \
    --cc=yi.y.sun@intel.com \
    --cc=zhukeqian1@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).