Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp219914imw; Wed, 13 Jul 2022 23:43:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t/SHT3jUfdZ9QxiQAKmL2Ui5OIzV/yqL1kDk+yv3QKhYA3pMSeQM+38G9yTbM53YErpZka X-Received: by 2002:a17:902:e78f:b0:16c:8741:fea1 with SMTP id cp15-20020a170902e78f00b0016c8741fea1mr5537698plb.89.1657781008085; Wed, 13 Jul 2022 23:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657781008; cv=none; d=google.com; s=arc-20160816; b=vGOYVSKSpMiBEoc8iwXLcdKnm0W9PAMmCnO2eY/jBcoy6x5ESIXOoVvUXxbqXPob4z ka3CXtFJpJkC1fap5u97sCQL1sp68WUtzcav+R7CG3tzHjtyr1K0BMDmCjh56AW3CZ0m PB1ArMKWoFCglZba9kmkxTaaWPtK4V3xPbl9DY9S9I01GiG2Sr3zxBJ0Rc12WOUCJCiz tCjcOipZXsepDI7/fw3Equ7VSkdya/mdwXAj+cwheBKJ0VyQ2eYzZziY9c4PQKE1NBtU zwYX+1AzqOww6xbBACpiiVENbIhjHVlEh+6dZV0ZSiwHLwTcPp+Y+8Ah8RLvuKML7qsw bsqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ae2SQEjyqEAy4llX3y9SCpo1YGcLcUs45qJqZjS/Fig=; b=d21248sB9crelKuhBCQ7f/6ZavIHHNFfGYQmU045//TMgLWTgr5pgQpEybBvwncf+4 X4gscFEK/0u/+LCz0KJLYE8KMGLWpAnps7ns3aGs3rBSoLgh6gGwUjX9FrR2oIRdXonK icXCYuXl+T9C5L0KihpegvRGK8O9POrOL95iEjmJ05l8In4+dqOlDlfx8qdZlzR+iJhZ HDu8nA2+9+0e3ZhBzdEAPLk7xxDnBzcKQe5AdRII+pSup+pcYhLn48QzZigbFQPydXOE jtAFXESZR/IulnTXcNCXu/W6y8+rfAgkRfeXzKhTFhE2axXPNAjV8QZFDPi25kiPl1Ex EC9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=N0SmdXZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a63dd14000000b004126f4d3ae0si902615pgg.290.2022.07.13.23.43.15; Wed, 13 Jul 2022 23:43:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=N0SmdXZQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234085AbiGNGib (ORCPT + 99 others); Thu, 14 Jul 2022 02:38:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbiGNGi3 (ORCPT ); Thu, 14 Jul 2022 02:38:29 -0400 Received: from mail-m972.mail.163.com (mail-m972.mail.163.com [123.126.97.2]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ABB179FC9 for ; Wed, 13 Jul 2022 23:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=ae2SQ EjyqEAy4llX3y9SCpo1YGcLcUs45qJqZjS/Fig=; b=N0SmdXZQh7th8Ak0L0HlF sHvbr6PHlrOpG4jUKjIJXEeOe/PSyANcLGhKl24MVIrVW+IqaNlFW8Y6NoffQ1Vf 1iCyOkMCeW6g4fLK7UQkogIv2J9CPZ9/eqQ9XvmcKhOhEl0mumoXDT1pFr7Xm75u NoRtO+B/ivsldJJLj7aXI4= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp2 (Coremail) with SMTP id GtxpCgCnJeS8uc9i1XzxOw--.21856S4; Thu, 14 Jul 2022 14:37:56 +0800 (CST) From: Jianglei Nie To: sj@kernel.org, akpm@linux-foundation.org Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jianglei Nie Subject: [PATCH] mm/damon/reclaim: fix potential memory leak in damon_reclaim_init() Date: Thu, 14 Jul 2022 14:37:46 +0800 Message-Id: <20220714063746.2343549-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GtxpCgCnJeS8uc9i1XzxOw--.21856S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7GFyfKr13WF1fXF1fXF1fWFg_yoWDGwcEyF 42qryUua1DXa9ay3ZFkw1fCw1xZrWkGrykXFWxt347AFyrGrn3Xry8Xrs3XF17u3yUJry2 vFs7Zas8Zr129jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRibAwPUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiFQU+jF5mLxy4NQAAsk X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org damon_reclaim_init() allocates a memory chunk for ctx with damon_new_ctx(). When damon_select_ops() fails, ctx is not released, which will lead to a memory leak. We should release the ctx with damon_destroy_ctx() when damon_select_ops() fails to fix the memory leak. Signed-off-by: Jianglei Nie --- mm/damon/reclaim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 4b07c29effe9..0b3c7396cb90 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -441,8 +441,10 @@ static int __init damon_reclaim_init(void) if (!ctx) return -ENOMEM; - if (damon_select_ops(ctx, DAMON_OPS_PADDR)) + if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { + damon_destroy_ctx(ctx); return -EINVAL; + } ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check; ctx->callback.after_aggregation = damon_reclaim_after_aggregation; -- 2.25.1