From patchwork Tue Feb 12 17:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 158165 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4088819jaa; Tue, 12 Feb 2019 09:16:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IZWttK3xq1dmwBgmhS/DI3VkYAv2H4x6OSKZLNo34rlARdrvF88rMXv9CGYbOxyYuC0gJye X-Received: by 2002:a63:ce08:: with SMTP id y8mr4501882pgf.388.1549991791341; Tue, 12 Feb 2019 09:16:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549991791; cv=none; d=google.com; s=arc-20160816; b=wM4JBV0EJ2f7o7NlXPB9x7iHF3c+xNWegR2XeJhWvP7dHTEUmAWVRrnr3ccxNpsanX MuU0z0FKJrDwlrzk2CksNfYj/a1xXso/GcxXYoPHwm9x3Bw1IxLpo10af+Cgx3sQZkZ9 V5j7YS8z1mBSNm95lzibzSQM/KOzz/GCtmC+G2T8YxESA/BDi8gf3IwjkOCwy/RNa+5M 5wdg4nt2rwv5xJ284Y0szsvaxp3o8MqxVceSpaidHkHo1RD/1Dak9p4KmO9S4fOUTv6n 5kKcwBI0wmYZF0TzR2ghqGzYPs4LL0suMCZKUxcZxTOnhyJ/xku2VjYokSglX8+HCxmM LCSQ== 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=V0vDEzF3Mc5eeutz94nbRQZ6xPyugJQXobqfjuLKiSM=; b=H6ZGBa3XZcATsM5NPnUxaA4TWxF4TjIj8Mis3u0o9UpOo5yActWplEyFEhTfsMLzsu vSOa2BloDpX/S8S4yJuus/521dPVzCi22vA6BWdrTGKPpoNkMqiOPR4KYCVCiF4TSQST MGeu5rxi+2aT/08m9BkrDODw45tG1IqqT/nL5uq17PHT/v74BQkAISHluEoBmyHKr5c8 rZHWCdplNdUTB6GWDAixmzFC1ibKRpf/EgoQd7rJtPXlMc+VL7W8mKwsDO6wGDws5xje l/QSkPU6Ii9L4yKkkPaXyA+6u+X9n1TdeTmfQJvp6vW0jb2tNl4t1aBnmC+v1zhSt7LL agPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cObDZdMv; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b136si7238277pfb.165.2019.02.12.09.16.30; Tue, 12 Feb 2019 09:16:31 -0800 (PST) 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=@linaro.org header.s=google header.b=cObDZdMv; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731791AbfBLRQ3 (ORCPT + 31 others); Tue, 12 Feb 2019 12:16:29 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40365 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731767AbfBLRQ1 (ORCPT ); Tue, 12 Feb 2019 12:16:27 -0500 Received: by mail-pf1-f195.google.com with SMTP id h1so1589538pfo.7 for ; Tue, 12 Feb 2019 09:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V0vDEzF3Mc5eeutz94nbRQZ6xPyugJQXobqfjuLKiSM=; b=cObDZdMvnlT9QoWFKtK5J0NH3yLnZBykk0W6O6czUdQ/wYALlhy+/89BGrRGgozWdD M9OBesQ2ZbzZmMEKzL3X5eFzKAfw5RToYyZFRGIjd7UT8ljdT3ekmZ0Up6mcbVozjiEL DRIx4WCIZNObHIFFf1/umNJU1yic69+R5q6hOLr5lBKjoZbkhQRA/D5TOqyaHIGld3P0 8GHrzUVTDPRgUxbcQ1vy63emJiAy7J9y22QOVf8fiOd/y9RtvBtd4uP88uwaPSFIQjzZ +IOKPHt++r1IAu+P5vmeWCbjTOrYh7HW/LAof8xPoCWlwi7DRfpbGyGAjn1nMIBgh2Md TFGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V0vDEzF3Mc5eeutz94nbRQZ6xPyugJQXobqfjuLKiSM=; b=ZYXMxD35uy1peE/1EFJOj01XBPWhD+f07fKQ1JUydo9kyFzPm78sP/yUGbdpPpffw3 onWjVmILE8nG5IZWTOXACPM3OAlQBsGILbUZ+OvIgnO6ifX+TKVBI8wuzPEZHIVKbKQc 9dcwmbq6RVYu12fty4YDpCRnsXHUxu0mXqEyP9LBUeT1ToMxewet6FKZW72LgiTQO3yR LUflvfV2R1OgTROXUHYU70sl+D2EyhZdlrktc38ugW31IKc/YiZkQCy7m1x6GbLO07uc tC3nxHZItV56GwZ6oNVK2uNo/kZPSKzw0f/kLWHWg/boooOuaoJIJKYz2MeyPPqvN0JT I1VA== X-Gm-Message-State: AHQUAuZ1zg5UItwFsaCRV7pMy3KaLEuqqRVlscWEDwQ/9XgRiVeYKBFI hYzVCqcW1o6tEDZ7RzTfwgsHxoshASI= X-Received: by 2002:a63:c345:: with SMTP id e5mr4571313pgd.103.1549991786088; Tue, 12 Feb 2019 09:16:26 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id z4sm8659231pgu.10.2019.02.12.09.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 09:16:25 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: suzuki.poulose@arm.com, mingo@redhat.com, peterz@infradead.org, jolsa@redhat.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/13] perf tools: Fix memory leak in error path Date: Tue, 12 Feb 2019 10:16:10 -0700 Message-Id: <20190212171618.25355-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190212171618.25355-1-mathieu.poirier@linaro.org> References: <20190212171618.25355-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Memory allocated for variable 't_params' isn't released properly in the error path of function cs_etm_queue *cs_etm__alloc_queue() and cs_etm__dump_event(), something this patch addresses. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 3011c6cae531..aac07f950074 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -175,6 +175,10 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, /* Use metadata to fill in trace parameters for trace decoder */ t_params = zalloc(sizeof(*t_params) * etm->num_cpu); + + if (!t_params) + return; + for (i = 0; i < etm->num_cpu; i++) { if (etm->metadata[i][CS_ETM_MAGIC] == __perf_cs_etmv3_magic) { u32 etmidr = etm->metadata[i][CS_ETM_ETMIDR]; @@ -206,14 +210,12 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, /* Set decoder parameters to simply print the trace packets */ if (cs_etm__init_decoder_params(&d_params, NULL, CS_ETM_OPERATION_PRINT)) - return; + goto out_free; decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params); - zfree(&t_params); - if (!decoder) - return; + goto out_free; do { size_t consumed; @@ -228,6 +230,9 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, } while (buffer_used < buffer->size); cs_etm_decoder__free(decoder); + +out_free: + zfree(&t_params); } static int cs_etm__flush_events(struct perf_session *session, @@ -379,7 +384,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, { int i; struct cs_etm_decoder_params d_params; - struct cs_etm_trace_params *t_params; + struct cs_etm_trace_params *t_params = NULL; struct cs_etm_queue *etmq; size_t szp = sizeof(struct cs_etm_packet); @@ -461,8 +466,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params); - zfree(&t_params); - if (!etmq->decoder) goto out_free; @@ -475,6 +478,8 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, cs_etm__mem_access)) goto out_free_decoder; + zfree(&t_params); + etmq->offset = 0; etmq->period_instructions = 0; @@ -483,6 +488,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm, out_free_decoder: cs_etm_decoder__free(etmq->decoder); out_free: + zfree(&t_params); zfree(&etmq->event_buf); zfree(&etmq->last_branch); zfree(&etmq->last_branch_rb);