From patchwork Sun Mar 22 14:50:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Su X-Patchwork-Id: 11451865 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 E2B7C174A for ; Sun, 22 Mar 2020 16:11:24 +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 0FA942072E for ; Sun, 22 Mar 2020 16:11:23 +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="LI7bVyKe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0FA942072E 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]:47950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG3C7-0003vW-2z for patchwork-qemu-devel@patchwork.kernel.org; Sun, 22 Mar 2020 12:11:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG1wR-0001Qu-Ta for qemu-devel@nongnu.org; Sun, 22 Mar 2020 10:51:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jG1wQ-00019l-R6 for qemu-devel@nongnu.org; Sun, 22 Mar 2020 10:51:07 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:52329) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jG1wQ-00019f-KW for qemu-devel@nongnu.org; Sun, 22 Mar 2020 10:51:06 -0400 Received: by mail-wm1-x341.google.com with SMTP id z18so2737162wmk.2 for ; Sun, 22 Mar 2020 07:51:06 -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=Y1e3vEeZseg8+tffx8tXcU2nLzJtVJ2tC5obRSC3QGo=; b=LI7bVyKe5czWJsGV+uRQF9JWbJDmo5KgN5iLT/+y/8AoTgRHfgkMW2Gh7Tf8VFGTmb czY0O6NKhslwx+ydK16GwBvdBnVwZxUolPlh8Nvy6G69SkeTPy6w+JF3qVEGAr8CUJLL zjuY4C3kWbYoXS6kcvXa3+jBij94eo4g0WKFc= 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=Y1e3vEeZseg8+tffx8tXcU2nLzJtVJ2tC5obRSC3QGo=; b=JyeJxzMaxm1m5ZN7KzqQTAl7Xs73N7+1iqVBNFKOnjmuG4G+QxUPJGcN8TStaowgw2 HTFa1noy4r9lYLqJ1IXf0feK1y+FqFZL2QdE0mPMQSKmj1p8drvtmDG7dSKy2AGunJiy 5H0eJGLyW5eTHhQnJdaaysfLsjZQu7sbuQ7AvV91EJZbQihCgqfAFtKC9GfYV7mScubf LtfHqpLN8cFMGnIUUzunMVcbWE1w1Y3Wfs85NNgfOS496YsC1hchCUwM7pBh0a/qzzRq PkGosjLfu6xdQwATr4isCkH+rWP4eOIZTQJPTh7gUmJ68VZ72r63WIQtFogoOeFoOQYz 3Vlw== X-Gm-Message-State: ANhLgQ2CbXd7vmWWKuUPZlsGEFPSwHgrQ3yFKo3uvAI5gSLgPepxmpmP BK3G31fRbiwuAehU8Q5pUmfpi3+72J1+a7lAXTDR5BaKmg91EQ== X-Google-Smtp-Source: ADFU+vty1ni2gML7F3qqZEYl0RIGp5SKsdo4foVPyDZdlZdKRNSjcKZzBPZi7KyZ7TOwMIrEnQIA3oKaU0FPZn1Fqv4= X-Received: by 2002:a1c:a70f:: with SMTP id q15mr22370775wme.66.1584888664940; Sun, 22 Mar 2020 07:51:04 -0700 (PDT) MIME-Version: 1.0 From: Derek Su Date: Sun, 22 Mar 2020 22:50:53 +0800 Message-ID: Subject: [PATCH 1/1] COLO: 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::341 X-Mailman-Approved-At: Sun, 22 Mar 2020 12:10:47 -0400 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(-) 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; Connection *conn; + int ret; if (mode == PRIMARY_IN) {