Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp178551imd; Wed, 31 Oct 2018 16:54:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5dEA7NupONzeiCLs5igRs8iD7FbvFdkKz5dIyn1Y2AsI3yvlBUjY8ZDRaW7Wturhl7NXUwn X-Received: by 2002:a17:902:7045:: with SMTP id h5-v6mr5344746plt.211.1541030065954; Wed, 31 Oct 2018 16:54:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030065; cv=none; d=google.com; s=arc-20160816; b=iGgqOt8WuXzPj3H7a7qQyC0tukQJVoKrJvpCecxox6xudxGzLYNHJzbKBKMppNYUcK OgVg+ccSb5uN3Xe1P0qH2awNFqaV2XIa69uSYBWC3X/pEcKEtLIZATFmBad792GuTw+f PRG/RCPxzqrpaz2FtsFn/LumSZghXR6p7ptErTofHxICa3a8bJcPBwiN8IlSDl4RLUsu xdoDDOeTZz3dpK9ZEW1Hbo57/UD/rDAqy8gqUmjQXSEhXNG6SkhR7JASNaOoU1IIsr10 4UryErKG0c/Z0LG044OMy4c8Jx6vGL1g49W/7m/es4VZxdGgFyyZZ26j2wjw2pOTzaC/ JTnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=v5w0irc70Kkrp7I1/7cMAkEXKLsBx45IoAlApff0KCA=; b=QYm5UFp+lGSI7suB+Bfvsv19bscqKJXKODwYB3xKKj/zUEj/iV9ssvs6qSRsxSecWL 6quajSF3UaVdPxq8DwsZEC5we7GhDQCOJ37ZlCafO0lLlL92z1YkETK8Q20qO3baWt99 NOILdXRMsv/0DrnehguoTJ44tXk1fhxOsyLo2MczDu2rotgEV4aRpsy8rp1+EsvqSZ83 06j+L5n53gSbGUgk1D4151yBJM4AF4XunVwEGzYJTukvtYS0xvaYrJdJwQ+FfnspBb3i m+nDqwOneQtxKSQY2Lvn4OXtT2ltLYvGhXbaz1HBCkaygIb5wTT9QHZiy5IweWdaLsqX RWBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zIUMMidF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3-v6si30520598plj.337.2018.10.31.16.54.11; Wed, 31 Oct 2018 16:54:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zIUMMidF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727673AbeKAIGL (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:52912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbeKAIGK (ORCPT ); Thu, 1 Nov 2018 04:06:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B808320843; Wed, 31 Oct 2018 23:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027159; bh=mS6VLy0+jU+Quwb3mDE6MzpA3VojBvi04BvSm6eZ4KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zIUMMidF3MSn6n2AjVJevLHDjUlpobbuhRvgziwc3w4PdzKyb7RBQXRI7QVKln3yk MxqNX5ukld1f/bb46pwAL0Zu0UHCaT49JmZzYLhD5YzNQgnHp9BtU4p2TKZ6ZA0kR3 +k+ToRwSBfQatcGGLz7k4mW7e34NYXmiPvVfDpCY= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sanskriti Sharma , Joe Lawrence , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 4.19 018/146] perf tools: Free temporary 'sys' string in read_event_files() Date: Wed, 31 Oct 2018 19:03:33 -0400 Message-Id: <20181031230541.28822-18-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sanskriti Sharma [ Upstream commit 1e44224fb0528b4c0cc176bde2bb31e9127eb14b ] For each system in a given pevent, read_event_files() reads in a temporary 'sys' string. Be sure to free this string before moving onto to the next system and/or leaving read_event_files(). Fixes the following coverity complaints: Error: RESOURCE_LEAK (CWE-772): tools/perf/util/trace-event-read.c:343: overwrite_var: Overwriting "sys" in "sys = read_string()" leaks the storage that "sys" points to. tools/perf/util/trace-event-read.c:353: leaked_storage: Variable "sys" going out of scope leaks the storage it points to. Signed-off-by: Sanskriti Sharma Reviewed-by: Jiri Olsa Cc: Joe Lawrence Link: http://lkml.kernel.org/r/1538490554-8161-6-git-send-email-sansharm@redhat.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/trace-event-read.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/trace-event-read.c b/tools/perf/util/trace-event-read.c index 3dfc1db6b25b..5eb1b2469bba 100644 --- a/tools/perf/util/trace-event-read.c +++ b/tools/perf/util/trace-event-read.c @@ -349,9 +349,12 @@ static int read_event_files(struct tep_handle *pevent) for (x=0; x < count; x++) { size = read8(pevent); ret = read_event_file(pevent, sys, size); - if (ret) + if (ret) { + free(sys); return ret; + } } + free(sys); } return 0; } -- 2.17.1