Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1908534imi; Sun, 24 Jul 2022 00:00:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t27P31+S+ilMRdj2Hz/QJmJ1B7N6/KBjFbDXhmeYLK7yWRw1nmhnKbkxyGMk0mskUJQWh+ X-Received: by 2002:a63:1648:0:b0:41a:49f9:77ae with SMTP id 8-20020a631648000000b0041a49f977aemr6435880pgw.377.1658646012249; Sun, 24 Jul 2022 00:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658646012; cv=none; d=google.com; s=arc-20160816; b=TS6W+6R7E4ADG19lEubqTJaIvmvTjaC6dfr/BjRKbvpvolxsXCB/oz5XHlE8OHTQ62 sPjecFjNV9pJ1Zh4CpdBrcmpOLq11FCYywcjyfIHiLzW5PjRiqDNbzhd81Sht4rsWlit yJ3tanYh7EgbfOw1LAlOcVxtOEq+K6E+r8LXDMBQW987+LeKkciRxj3cau5RkSRYKBi2 n0F/3QKNpSTdQBEpymNXUq0HVRn0iYQT9d/DQdCnAyijBibf9lz4DwaEIehqXgSTk1HB FTEwb8sc+y3GEFUUGzC9FMI1DTvRC+Q2hI9rEnHDKAwyrSeL7Lh7z6NZ+XY16yhE/2FR 4PWg== 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=Dx2LdmmelaSG129Gndk1nriYSQBQ1KJZz167f8rv7V0=; b=dDPStiZvG3C7/rQN5MdqKIqyDIatjnrLn/GmqFCfvOVVybnmWv7NUnoCt9JLRZX9k3 5RVb8NqmJjZ0H+MHkyYXM4AtGP9Ib7JGC+6G+xJSQ4+lPw07BA7D0u+HmR1D/tyOX8wQ oBl18pTGMagWq5H0+VDXERwccxmDGZEawsych4lOehO4rWuCzA6GQ6msfit5MrHBW4QE dcOJWHMm+i/felroZ2mZL1Lq+IYcTtrVZ5yrykIslIhFja/7luUjkOAqdz/rHLoXDZK0 WC+/w+jFgdVxvB6I0+s3pkB8U0vAhsM9WVHzuar5+dWH6Ki6YKrP7278lKOiwfsGpTqS b7Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=D911up3l; 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 f62-20020a636a41000000b0040d275d3fcesi10523093pgc.661.2022.07.23.23.59.50; Sun, 24 Jul 2022 00:00:12 -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=D911up3l; 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 S234667AbiGXGxe (ORCPT + 99 others); Sun, 24 Jul 2022 02:53:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbiGXGxc (ORCPT ); Sun, 24 Jul 2022 02:53:32 -0400 Received: from mail-m971.mail.163.com (mail-m971.mail.163.com [123.126.97.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF75A18B00; Sat, 23 Jul 2022 23:53:29 -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=Dx2Ld mmelaSG129Gndk1nriYSQBQ1KJZz167f8rv7V0=; b=D911up3lsqiL0jdoI26JR yYjcKRZI5nv1gDQF0P4jbLZqx47PsFfycw9PALK4cHmT9f1ncX7luVBCHV4BAox6 oSpfev8rkwqCt2k4j3dRHLVgbhQjSC1yzHEx9yzkAmNSEkucuISCx1zTEDa2OrzZ VIr6eZSWEH+bAJ2Dt5aM2A= Received: from localhost.localdomain (unknown [123.112.69.106]) by smtp1 (Coremail) with SMTP id GdxpCgCHoeQq7NxidFSvQA--.22213S4; Sun, 24 Jul 2022 14:52:41 +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, stable@vger.kernel.org, Jianglei Nie Subject: [PATCH] mm/damon/reclaim: fix potential memory leak in damon_reclaim_init() Date: Sun, 24 Jul 2022 14:52:24 +0800 Message-Id: <20220724065224.2555966-1-niejianglei2021@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GdxpCgCHoeQq7NxidFSvQA--.22213S4 X-Coremail-Antispam: 1Uf129KBjvdXoW7GFyfKr13WF1fXF1fXF1fWFg_yoWkGFXEka 12qr9rua1DXayFy3ZrCw1fGr1xZrW8GrykXFWIy347AFyrKrn7Xry8Xrs3Xr17u34UAry2 vFs7Zas8Zr129jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRibAwPUUUUU== X-Originating-IP: [123.112.69.106] X-CM-SenderInfo: xqlhyxxdqjzvrlsqjii6rwjhhfrp/1tbiWxlIjGI0VkuIuQAAs8 X-Spam-Status: No, score=-1.8 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 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. Fixes: 4d69c3457821 ("mm/damon/reclaim: use damon_select_ops() instead of damon_{v,p}a_set_operations()") 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