From patchwork Fri Feb 15 00:45:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 158459 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp103680jaa; Thu, 14 Feb 2019 16:47:53 -0800 (PST) X-Google-Smtp-Source: AHgI3Ia2A6Dw6h9ZQ6WVrq0ZBG7BvskKb9K6Y9XgObBeze2Lbz70dPmKK+Nlre9NMqf5U5tHqPaa X-Received: by 2002:a62:60c7:: with SMTP id u190mr1950890pfb.180.1550191673838; Thu, 14 Feb 2019 16:47:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550191673; cv=none; d=google.com; s=arc-20160816; b=aGyCDvY1HPFmT1u7RVikzMLp8fDdwfi6ueCbwA0GDx4uqhkqG3UUE7/lMTmo7UUWs+ 1+TLYXxiLpc83kfE4kYuGLSG07VmMVFg4CRcrCLFBJqB4ZO6m6ambWfr0ONVLzCaNoC1 2LNQ/5RL8nbqcJoYJOslJ4R0Iq7yAE1fnR9pb7gUPrpfO5kywkHGA3jypCK2j+Pl7FXc qF2SPeohTkWWPkOcleYiVCz+IxjIATiyP9br9q0STz8GhY1zUWA0BkTwk1W7VrfkgHbS sXBH3bTf54vdHn0IqqvZcUYqSu7oyV2/QQ+dmrg5K2QVzlKWZg3Aflp3yF+MKXhzLRjA m9rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i6OkLRdtAldLsIpdJN8Vv5mrhz56uZ3mV2R6jqLJXXE=; b=f7Ejlm05rMqxqEQJLaTPv++SmoyUr+OrOJg+xkWKlFXqTaBMjIgqgNLyIeF3pxhnaY dDqtGRdxWpesZNTBWehZ9Jvr3RyM4DYFfmKOyq+SJBbD5rBYbL/rDXdeDNq+msq67Nku kycFBvy1CGKfzJLJ7BN3nqa1PYfDUOXtrDa00wP34RZ3rR7aNs3/fQqaWM7txzcG/lUn 2xVcnWRhVsrkyQfjx+IjEqnk5jMGrcm1TeBzVAG1gBag0Z9gG68IQjn29BcfH9vIEaY+ kw1gWfesit37H7pOKaz1JQUKtk8xGAuXcGsblXVnWhRZmDSrEnBvyxt16DxNbJ7gNABM xosA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FvhgmoLi; 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 z9si4031375pgf.54.2019.02.14.16.47.53; Thu, 14 Feb 2019 16:47:53 -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=@kernel.org header.s=default header.b=FvhgmoLi; 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 S2389344AbfBOArw (ORCPT + 31 others); Thu, 14 Feb 2019 19:47:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:46596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389377AbfBOArq (ORCPT ); Thu, 14 Feb 2019 19:47:46 -0500 Received: from quaco.ghostprotocols.net (unknown [189.40.103.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBF36222D0; Fri, 15 Feb 2019 00:47:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550191665; bh=59/Jn+pGlKT7JzKEMbIhX3CYYQrWCvYqFcJL9XeciIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FvhgmoLipdaH5yxlQDP9ynnnPY0u5qu5F3dhw/fttZ6B/bnoTDQcOyXeBsgKQY/+T j2kK7SlFj6CJDvVgYGrHLPBaPfCr8axPhuxoBe9wIGgDmmp9kn/qhc6lfU6Wbwe6yK A4yfOZakYbHAn1Ag7SA1DjExUIhCZWi+ZS7lrl88= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Mathieu Poirier , Jiri Olsa , Leo Yan , Peter Zijlstra , Suzuki K Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 27/43] perf cs-etm: Fix memory leak in error path Date: Thu, 14 Feb 2019 21:45:23 -0300 Message-Id: <20190215004539.23571-28-acme@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215004539.23571-1-acme@kernel.org> References: <20190215004539.23571-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mathieu Poirier 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 Cc: Jiri Olsa Cc: Leo Yan Cc: Peter Zijlstra Cc: Suzuki K Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190212171618.25355-6-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) -- 2.19.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);