From patchwork Tue Jan 14 02:29:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Ye X-Patchwork-Id: 13938330 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 536C1C02180 for ; Tue, 14 Jan 2025 02:29:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C68DD280005; Mon, 13 Jan 2025 21:29:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C1823280001; Mon, 13 Jan 2025 21:29:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADF50280005; Mon, 13 Jan 2025 21:29:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 90142280001 for ; Mon, 13 Jan 2025 21:29:46 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 34EC2C0566 for ; Tue, 14 Jan 2025 02:29:46 +0000 (UTC) X-FDA: 83004476772.16.4FFA5EE Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by imf30.hostedemail.com (Postfix) with ESMTP id 2D5B78000A for ; Tue, 14 Jan 2025 02:29:42 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liuye@kylinos.cn designates 124.126.103.232 as permitted sender) smtp.mailfrom=liuye@kylinos.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736821784; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=rFLG6LoHAiJ6rUXDhNOkBZ1O/ZzpPdYhCN+q3WCE4sA=; b=KkDe5bvTcHuzMdH1qwtk/lk5OWnDHSeX3ErnJTeob+j0VsR6BU+cyEAhjX2mYD93CWRllj b5sk4ilBYdMvmjR3SAm3nDzxwo6RuvS8bvCaIzxEnfrm40HcxNcZJpVfHS/aqS+cm/fOtK UNHvtrHOAhwf6Rzo8LTUTQ7J+3aJnJU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of liuye@kylinos.cn designates 124.126.103.232 as permitted sender) smtp.mailfrom=liuye@kylinos.cn; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736821784; a=rsa-sha256; cv=none; b=rtHcg0Ua0qSXMermAOvkA94gB+QKGLcry/jb64L0Zql4ilCcdq9jxq44Avvqj8rtuehGK2 VZvcCqwo7rJnxotQYFLjddyAlQRvmWOaaoweoGf0LouwaBM11ltqe4OJdPGWyxCEroRXEz KZnj3v1K9aw+OsOBQ1egQSC+SErW+1w= X-UUID: 661db11ad21f11efa216b1d71e6e1362-20250114 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM, HR_SJ_PHRASE HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT, HR_TO_NO_NAME IP_TRUSTED, SRC_TRUSTED, DN_TRUSTED, SA_EXISTED, SN_EXISTED SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD, CIE_GOOD_SPF GTI_FG_BS, GTI_RG_INFO, GTI_C_BU, AMN_T1, AMN_GOOD AMN_C_TI, AMN_C_BU X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.45,REQID:e6da6398-c88e-48e1-aae0-2cf1fd4f9916,IP:10, URL:0,TC:0,Content:46,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:66 X-CID-INFO: VERSION:1.1.45,REQID:e6da6398-c88e-48e1-aae0-2cf1fd4f9916,IP:10,UR L:0,TC:0,Content:46,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Spam_GS981B3D,AC TION:quarantine,TS:66 X-CID-META: VersionHash:6493067,CLOUDID:f0aad51c684a930b438bf3ec02af1efb,BulkI D:250114101207A7VC4N0T,BulkQuantity:3,Recheck:0,SF:17|19|24|38|44|66|78,TC :nil,Content:4|50,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:40,QS:nil,BEC:nil ,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_FSI,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-UUID: 661db11ad21f11efa216b1d71e6e1362-20250114 X-User: liuye@kylinos.cn Received: from localhost.localdomain [(223.70.160.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 679831835; Tue, 14 Jan 2025 10:29:37 +0800 From: liuye To: akpm@linux-foundation.org, shuah@kernel.org Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, liuye Subject: [PATCH] selftests/mm/cow : Fix memory leak in child_vmsplice_memcmp_fn() Date: Tue, 14 Jan 2025 10:29:29 +0800 Message-Id: <20250114022929.46364-1-liuye@kylinos.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2D5B78000A X-Rspam-User: X-Stat-Signature: 63skfidbtkkkm576xo5o8tryz671xfit X-HE-Tag: 1736821782-942991 X-HE-Meta: U2FsdGVkX19Do3PcUwBLvvmXU58C2rPrYj+vjKg6fEPxYyb+dLkrwNSII+MLWT/uJ3tF0GE//LLAqnYYDqNsa2JnsVXRghtJfTm3vWTfzTtC58Zo0sY9SBbKkvD0pdWdJk584dYCcpwGefLHnQ183b3I1kpEyRLie/HWZBulgBd+UioAhhxh6ui2T3BIMvdKAc12lkDO+SDji0iX/S52BHraexFddXvEMd/vwpyE3rp9D8ixy32gujXJTfR28g8DxSbaFlwCVByuqYHXie/Ep1A1b7PkiN1K2ZdeGaCXVnRKjx5EvdZBHkemdT5m2nry86qG38bvf5UpRN1IV5pDPrMTQwtuPxbj5g6KULhVkbH7LwcZeQOrBRcvnkFNSrxxPuIYx660E5grjkJG5X4aHukS4caY2XoJGbD6+PNThfG7Q1FIfDgC5UrKSZKj/+JOiO2YUCSc+Ovd1zj3NR82S3SW5EvqKqhkNgknvtYkp8g9b6Wo1r4L6eRltt6VP6HPoSgJhiFCiwxv4WSRm5erjxew/WfqWiIjbmTCHQx2h4ffYTQmvgDogNeb0H8Wk3C503u279MFUO0onebzmoDMPfbkHrs13T71XwcUNJeLu8vOIXczu5QT0DmeY/HHA0XtQ5MuApDeFdGoutSOG85TfaVOqLdp1/QCAk7ALqWhrSbPveTHltjgL5rKwW/ZgQ08bPvJo759lPDuHpr+AyoJYM+GrJRVOQGgYnke7iVz+vvDesT5G/PvR7Ul1aErJvQ7E40SH8TcZO73xGdLBY7B+2GL3+Q7Q63rNLhuLWfiMZGP6P7N+/OnuOPODvg9TOA7qGT6qsYtlfCa9wXFZgr9Sc6p6rhRR8g7UgToVF4t4f6+nCsloARoYv5a6qOtpdyvrSJsc+GS+mujXTQd+t1yhamfURUgWoxS5LK+thA6prFq6vKc/g1ianpU3/g/oxWp4MVOsAFkhTm6tZCtgAw UVIB2FUv oz+rHEdJou4abu8geyeNwfcoOLXUn/M3uevpqhbH5KuRC79rSLJUwVvWU6LiNOWrTLz2zRyRI5DJhHWk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Release memory before exception branch returns to prevent memory leaks. Signed-off-by: liuye --- tools/testing/selftests/mm/cow.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c index 1238e1c5aae1..959327ba6258 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -167,19 +167,30 @@ static int child_vmsplice_memcmp_fn(char *mem, size_t size, /* Backup the original content. */ memcpy(old, mem, size); - if (pipe(fds) < 0) + if (pipe(fds) < 0) { + free(old); + free(new); return -errno; - + } /* Trigger a read-only pin. */ transferred = vmsplice(fds[1], &iov, 1, 0); - if (transferred < 0) + if (transferred < 0) { + free(old); + free(new); return -errno; - if (transferred == 0) + } + if (transferred == 0) { + free(old); + free(new); return -EINVAL; + } /* Unmap it from our page tables. */ - if (munmap(mem, size) < 0) + if (munmap(mem, size) < 0) { + free(old); + free(new); return -errno; + } /* Wait until the parent modified it. */ write(comm_pipes->child_ready[1], "0", 1);