From patchwork Wed Feb 15 08:34:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 728094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vNXgt6Nkhz9ryk for ; Wed, 15 Feb 2017 19:36:26 +1100 (AEDT) Received: from localhost ([::1]:39055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv4Y-0000yR-8V for incoming@patchwork.ozlabs.org; Wed, 15 Feb 2017 03:36:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdv3B-0008Ew-R9 for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdv37-0007Zg-5m for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:57 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:44864) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdv36-0007Th-Im for qemu-devel@nongnu.org; Wed, 15 Feb 2017 03:34:53 -0500 Received: from 172.24.1.137 (EHLO szxeml430-hub.china.huawei.com) ([172.24.1.137]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id CPF49041; Wed, 15 Feb 2017 16:34:42 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml430-hub.china.huawei.com (10.82.67.185) with Microsoft SMTP Server id 14.3.235.1; Wed, 15 Feb 2017 16:34:35 +0800 From: zhanghailiang To: , , Date: Wed, 15 Feb 2017 16:34:15 +0800 Message-ID: <1487147657-166092-4-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1487147657-166092-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1487147657-166092-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 119.145.14.66 Subject: [Qemu-devel] [PATCH 3/5] colo-compare: release all unhandled packets in finalize function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhanghailiang , xuquan8@huawei.com, qemu-devel@nongnu.org, pss.wulizhen@huawei.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We should release all unhandled packets before finalize colo compare. Besides, we need to free connection_track_table, or there will be a memory leak bug. Signed-off-by: zhanghailiang --- net/colo-compare.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/colo-compare.c b/net/colo-compare.c index a16e2d5..809bad3 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -676,6 +676,23 @@ static void colo_compare_complete(UserCreatable *uc, Error **errp) return; } +static void colo_release_packets(void *opaque, void *user_data) +{ + CompareState *s = user_data; + Connection *conn = opaque; + Packet *pkt = NULL; + + while (!g_queue_is_empty(&conn->primary_list)) { + pkt = g_queue_pop_head(&conn->primary_list); + compare_chr_send(&s->chr_out, pkt->data, pkt->size); + packet_destroy(pkt, NULL); + } + while (!g_queue_is_empty(&conn->secondary_list)) { + pkt = g_queue_pop_head(&conn->secondary_list); + packet_destroy(pkt, NULL); + } +} + static void colo_compare_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); @@ -707,9 +724,12 @@ static void colo_compare_finalize(Object *obj) g_main_loop_quit(s->compare_loop); qemu_thread_join(&s->thread); + /* Release all unhandled packets after compare thead exited */ + g_queue_foreach(&s->conn_list, colo_release_packets, s); g_queue_free(&s->conn_list); + g_hash_table_destroy(s->connection_track_table); g_free(s->pri_indev); g_free(s->sec_indev); g_free(s->outdev);