Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1363666ybg; Thu, 11 Jun 2020 08:00:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXAG3DqrdxiCN4QUx5394pq0DRhPBKJfN4OZPKVFbgRYIxR5DFoIpfuiWY5uSkVZIfIndl X-Received: by 2002:aa7:c496:: with SMTP id m22mr7472733edq.187.1591887653760; Thu, 11 Jun 2020 08:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591887653; cv=none; d=google.com; s=arc-20160816; b=xFNqFeZ6uwAVbR15A+ZQ0pvjKaTkPZLRTCSKQ3mFIt2sysIUSe/YkyLcW6zF+u4SCK Na1F3ok2Xr33s8oyx6WmCAoApe5P8UL7F/hJ0UkAgJFw8zFuju0JKt00LnT423WciVvW H3HEMYTYLpUpC64Vq7JwS993qgyKySNyH3cZ40DHn9NZuQ7UKjNPgqCf6gtMN5+R8SG1 scFot4OJKRTOBqFz0955Wk91AkSDJBtNftoSfw/YcMaQj0PiUnFTBHS/oiSWL5vSAIyR zgonO64k+imkRIJQ4e7t/SZadVmJD1wXC/evVydcbsAX2+hTxCz+lodV/UWluRpNPDbs jcKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=k3c6ccoPga5efaHPM+5xazWq4PzlriZSQpqyZwxWuXg=; b=o6t9vbEHwjoxOsZVwnStcCqh6NvSbdmxIdoJuScGNIKJ0YV7fTHxEoxgyOpyeRLZAi gcfvV0JdEkBIM37vR+an147mnEJ8+Xd0MsCBCb76hewDQ13+m3dHS9/IRaUr9MgKCXgj WtPBHRBVQ4wolHRLRTRY6g9RGdRem7eUKoDBw0RgOc1k00xPFkyWpbfSVZ5IIV1FmIO9 gGYGA2Z6S6/9Ccniyn6fyfmxofH+FWH2i1OS4mmRVqJjli1BXYcFVxdQ5oQgwHrqq+zR sP0fhhzOF755iRr4KKT0nkOWCUbn+JNPhCTBy17H2XDDlTinNmGO1Tkd5KQqWce1nnja nTiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si1958806ejb.4.2020.06.11.08.00.26; Thu, 11 Jun 2020 08:00:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728420AbgFKO4z (ORCPT + 99 others); Thu, 11 Jun 2020 10:56:55 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5820 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728104AbgFKO4z (ORCPT ); Thu, 11 Jun 2020 10:56:55 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id DD49488854E444E97BE3; Thu, 11 Jun 2020 22:56:40 +0800 (CST) Received: from euler.huawei.com (10.175.124.27) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Thu, 11 Jun 2020 22:56:31 +0800 From: Chen Wandun To: , CC: , , , , Subject: [PATCH next v2 1/2] perf tools: fix potential memleak in perf events parser Date: Thu, 11 Jun 2020 22:56:04 +0800 Message-ID: <20200611145605.21427-2-chenwandun@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200611145605.21427-1-chenwandun@huawei.com> References: <20200611145605.21427-1-chenwandun@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.27] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cheng Jian Fix memory leak of in function parse_events_term__sym_hw() and parse_events_term__clone() when error occur. Fixes: b6645a723595 ("perf parse: Ensure config and str in terms are unique") Signed-off-by: Cheng Jian Signed-off-by: Chen Wandun --- tools/perf/util/parse-events.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 3decbb203846..6f4dc8a92817 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2957,8 +2957,12 @@ int parse_events_term__sym_hw(struct parse_events_term **term, sym = &event_symbols_hw[idx]; str = strdup(sym->symbol); - if (!str) + if (!str) { + if (!config) + free(temp.config); return -ENOMEM; + } + return new_term(term, &temp, str, 0); } @@ -2983,8 +2987,12 @@ int parse_events_term__clone(struct parse_events_term **new, return new_term(new, &temp, NULL, term->val.num); str = strdup(term->val.str); - if (!str) + if (!str) { + if (term->config) + free(temp.config); return -ENOMEM; + } + return new_term(new, &temp, str, 0); } -- 2.17.1