From patchwork Sun Mar 22 16:23:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 11451911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AFBB1744 for ; Sun, 22 Mar 2020 16:24:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 300602072E for ; Sun, 22 Mar 2020 16:24:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=qnap.com header.i=@qnap.com header.b="S2ButO8J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 300602072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=qnap.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG3OK-0000gQ-AK for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 Mar 2020 12:24:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46249) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG3Nl-0000EZ-CL for qemu-devel@nongnu.org; Sun, 22 Mar 2020 12:23:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jG3Nk-000445-06 for qemu-devel@nongnu.org; Sun, 22 Mar 2020 12:23:25 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:43189) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jG3Nj-00043b-N7 for qemu-devel@nongnu.org; Sun, 22 Mar 2020 12:23:23 -0400 Received: by mail-wr1-x442.google.com with SMTP id b2so13620833wrj.10 for ; Sun, 22 Mar 2020 09:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qnap.com; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=TlkvLQvZ1qn4FRJTnFFvr/g0Nw5gDr0bOnHpcyROG2A=; b=S2ButO8JAa81PXJtqxbWyGYjptfZ5CB/cYyJspS7lHlluh/s41NHlh3ewmYb0Lgz2Z 3OM9C4lF/hFXLv7qOmz1AS0X+FGDRjPZ31LwyrshCQWyZedNqbEKopscOKzKh5jt0GN+ B9iGzzmrGUovsiTWpfZ5T/lXZ9VTknEFWymok= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=TlkvLQvZ1qn4FRJTnFFvr/g0Nw5gDr0bOnHpcyROG2A=; b=mIRuItPTh2oXJwyIOBn8Bom+fS9BvKCI2bzbhxzgfLGEIV8pXZVOaK6aPndoynvc2T DFl/hmK14wwq6I/tW5reAMXplDsyJ6c4sH0EqF2Wq5o66HRtTGQvRwoFfjZaJQvZrlyW Ssw1cvK7I4GV+NNQ5y4izSVVrUYBjm4zBsmaMOFDNFxwBEAlqE1cWlCrWwp5tNuhUwze /YqzDkb5JYewxL8fFHDtCgAbdw20KDF7u5h6FqgNn91x/azY2C02J3tMBvkrq/cxkHY9 RglKicHAxeDnR7qb6C+zmEvFnZhn+FUp30gO8zW6UCFjBRVQYc9f+OkUo3HVtyBE5UFo noOA== X-Gm-Message-State: ANhLgQ3KiyI6F+uG80ruvxwMJESdm1VydaDZ4WIMqi5JdeC7VlEXW8HD c+Bsolw4NIDsNhHUrkQ0E9oLuPBZt/20+qlCZUpgstftbZURow== X-Google-Smtp-Source: ADFU+vusOYfEHscebN0/sfwwboqo4vauju1iGjK67cJvWauo7zkc4SxyMKn+3gjLR5I6pwiHhYgPMa8cx/Yb+hpgAqY= X-Received: by 2002:adf:e5cd:: with SMTP id a13mr24729416wrn.275.1584894202031; Sun, 22 Mar 2020 09:23:22 -0700 (PDT) MIME-Version: 1.0 From: Derek Su Date: Mon, 23 Mar 2020 00:23:10 +0800 Message-ID: Subject: [PATCH 1/1] net/colo-compare.c: Fix memory leak in packet_enqueue() To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: chen.zhang@intel.com, jasowang@redhat.com, lizhijian@cn.fujitsu.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The patch is to fix the "pkt" memory leak in packet_enqueue(). The allocated "pkt" needs to be freed if the colo compare primary or secondary queue is too big. Signed-off-by: Derek Su --- net/colo-compare.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) Connection *conn; + int ret; if (mode == PRIMARY_IN) { pkt = packet_new(s->pri_rs.buf, @@ -243,16 +248,18 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) } if (mode == PRIMARY_IN) { - if (!colo_insert_packet(&conn->primary_list, pkt, &conn->pack)) { - error_report("colo compare primary queue size too big," - "drop packet"); - } + ret = colo_insert_packet(&conn->primary_list, pkt, &conn->pack); } else { - if (!colo_insert_packet(&conn->secondary_list, pkt, &conn->sack)) { - error_report("colo compare secondary queue size too big," - "drop packet"); - } + ret = colo_insert_packet(&conn->secondary_list, pkt, &conn->sack); } + + if (!ret) { + error_report("colo compare %s queue size too big," + "drop packet", colo_mode[mode]); + packet_destroy(pkt, NULL); + pkt = NULL; + } + *con = conn; return 0; diff --git a/net/colo-compare.c b/net/colo-compare.c index 7ee17f2cf8..cdd87b2aa8 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -120,6 +120,10 @@ enum { SECONDARY_IN, }; +static const char *colo_mode[] = { + [PRIMARY_IN] = "primary", + [SECONDARY_IN] = "secondary", +}; static int compare_chr_send(CompareState *s, const uint8_t *buf, @@ -215,6 +219,7 @@ static int packet_enqueue(CompareState *s, int mode, Connection **con) ConnectionKey key; Packet *pkt = NULL;