Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1123574rwp; Thu, 13 Jul 2023 06:32:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHRavzrDc8+2SvReCY4S9ZE5aa9YrQYDNOZDTxY/YIrA7yOHnYZx9ZLC+VNbZHMbG/F8FJ7 X-Received: by 2002:a05:6602:2186:b0:780:d338:5373 with SMTP id b6-20020a056602218600b00780d3385373mr1747760iob.15.1689255152925; Thu, 13 Jul 2023 06:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689255152; cv=none; d=google.com; s=arc-20160816; b=sInvwb1M9uwltFu8N1QLlkBLCWx7gEhOXHItHlM5OAr+8Zg1IfaIR79ceAAC/ogtqv 5/IT0lDIgKxLZDYBh1HTA50+G83xTP+OThcLhXe2uPN0LLF8gcqDDGlJMTFLAMFPrllA FH2qttHEdB1DOc2IX14u9Ia2ZZKo+fLqHgqz8FpeeTCRgICei7dZIRUSor/i6ml7q9HD fU0yAJZ5qvzF2gsCEd32y5ZwUaKfog6S3+tMC+AmG4II7t/i8l1l9w0GWo6XGyzxApHP l9OmYxSGmiN8fagEfjJnY/ZzZKsZnyWRTfcu22VO65f1E6yh+4KJ0dQLUKz7U1yRwKP3 fX6w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m3b7ZAhCMxSN1BcImyV0DQCirPKWDf2KMZx9LMdHM2Q=; fh=JGvS7F4GRFByFUotgL/hNTn+YJdI1o7ASnYprHkHKig=; b=MhVdtbVXTX3FlMTdKsIKiLtGMp2z/iHmBJ55w8OmxXbMFANBMRi/WQwkA23mv1+MPR hCplzkHWbUb1Oj0xruknMdKtfwyWmmKuVjGhI03CBHt7nn1cEFrUm/qwf/LsmVvPgL8k mZBzLrgEtethIqkUYcy5amR2tEde/Fn9rWOBbYbChYfeCms1W8k64Rwq2xl9hd+6+vV+ zwO+5FcKa/x48U/KId0gLO3jlxfK98s8OqXy78MqN78pVsl5pHpuj6X8i+nMuUFIlEn3 Xl02uxiD4tBrUAmzqWfnwWXdW2oLcA7OCfIEx9HZMjLQztnuChc7meLcW9Hte4cM+gU5 FGNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dfi3BudE; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i69-20020a638748000000b0055c8b57537fsi921150pge.30.2023.07.13.06.32.20; Thu, 13 Jul 2023 06:32:32 -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=@intel.com header.s=Intel header.b=dfi3BudE; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233436AbjGMNUt (ORCPT + 99 others); Thu, 13 Jul 2023 09:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234797AbjGMNUa (ORCPT ); Thu, 13 Jul 2023 09:20:30 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 553572D7D; Thu, 13 Jul 2023 06:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689254423; x=1720790423; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eyfFQOIKAZuYYHklcPqdTE2gmRhrKpH4qZtrSJz6apA=; b=dfi3BudECKBmEr/Ori08aoyjCFjc9CciZYn/IlKMbXY717cJXuBMErzh rfgWVfavlAU9ldNMgjHDB05cRSzbpJnb8XFGoS6Y7DalpXNX0bqjtkW4x NGGw+SD6RqZM8OH+U1euXqvurBeqBN166rxoC7iyq2uU5GR67QM43KKsi +433hXBrDhmCksx+D9Y0bEfzg0Do05v+NypgOJ4/sqb4Hwuwj+wyvVMlj pvufA+mRf0+Iyd2g5wH3gOPfjN8umvzdLHpKslkK5dky0yNiwtvHmBtN0 dQNsNstcqNgEE5EFU5CHuJ0GTLWF4KH/NancnkDsObwfkImE4xiQ1Jz8j g==; X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="345496538" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="345496538" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10770"; a="968615700" X-IronPort-AV: E=Sophos;i="6.01,202,1684825200"; d="scan'208";a="968615700" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.222.39]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2023 06:20:20 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-kselftest@vger.kernel.org, Reinette Chatre , Shuah Khan , Shaopeng Tan , Fenghua Yu , Colin Ian King , linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v4 02/19] selftests/resctrl: Don't leak buffer in fill_cache() Date: Thu, 13 Jul 2023 16:19:15 +0300 Message-Id: <20230713131932.133258-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> References: <20230713131932.133258-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 The error path in fill_cache() does return before the allocated buffer is freed leaking the buffer. The leak was introduced when fill_cache_read() started to return errors in c7b607fa9325 ("selftests/resctrl: Fix null pointer dereference on open failed"), before that both fill functions always returned 0. Move free() earlier to prevent the mem leak. Fixes: c7b607fa9325 ("selftests/resctrl: Fix null pointer dereference on open failed") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/fill_buf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c index 341cc93ca84c..3b328c844896 100644 --- a/tools/testing/selftests/resctrl/fill_buf.c +++ b/tools/testing/selftests/resctrl/fill_buf.c @@ -177,12 +177,13 @@ fill_cache(unsigned long long buf_size, int malloc_and_init, int memflush, else ret = fill_cache_write(start_ptr, end_ptr, resctrl_val); + free(startptr); + if (ret) { printf("\n Error in fill cache read/write...\n"); return -1; } - free(startptr); return 0; } -- 2.30.2