Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1358600ybj; Thu, 7 May 2020 22:42:22 -0700 (PDT) X-Google-Smtp-Source: APiQypIRNsDlpFROnjYfVoDIllqRDVgqv4TQf/gtnv5yzWKIURzfWSul5gdAnIyv6E8bAEOseToL X-Received: by 2002:a05:6402:8ca:: with SMTP id d10mr771377edz.167.1588916542410; Thu, 07 May 2020 22:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588916542; cv=none; d=google.com; s=arc-20160816; b=GdraBY+570WSKLrKjMrJ4JwdlVHq4LVr1AfrfSoFbsBezJzzJ153rOOV9K2BU7PJud OlzXeLhYePF7W+1Qd8jPsCdpr/rIhhEcR8JLzwYmxmZxJMyUELD+uukk0SQ4CpXTIrJ6 aeMXreagAxnRSq3XkSZvreuFl4tjb8r74XXMhmRn3SpyoL4nsVJ8dikt3skOmD8RSk2T JtQtBErTUlEzDt3hQ+oMj7vG6Vhv09jk22N9VB5twQdq/UNDmVI0Cakh9Fbw5G8oUR3n aXonDhDpjoJB2t3iW1L3QJoVay9nPP7ak7Xi7T8YDKM+dNqof+KFVQ6Mf2wztrK0M/2r +Gew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=kf/Nl54LdD1Myd4Q2ihfierbY9Agfscu2MTKHIAamr0=; b=AVjCBM2GkqlDRVoaGGHSo4Im8rfjVJ80iQguOYpdBA0WkokIrhBfjGth/casjyTCXb 6TT9X4OsfJvzjmAziheHRLIh4G8zhTw/YXhRhyvkj0xGOhIO2zH0lHzBoomA/y7+Hjs7 K+v5CcplzZjcuPYq5i1q+afHp+k4z049Pf6uAvbTJeqQ/RfXAvNChmQK02z08+p0MbUU 9j+oWBTadRONbnpdZcDD7wtC3V0rbKV6iKwqgG4xQcDy/TYgJdnuHoJLA27B260+QixT IDQVxASSOoBm9RZaOOJh1zvRcF260ojuL2NvviYiyJYIEgfFiH4x/Uso9dSVROHs1uo4 sfHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s3XhVoaJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si399045edg.244.2020.05.07.22.41.59; Thu, 07 May 2020 22:42:22 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=s3XhVoaJ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbgEHFht (ORCPT + 99 others); Fri, 8 May 2020 01:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727072AbgEHFgn (ORCPT ); Fri, 8 May 2020 01:36:43 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B295C05BD0C for ; Thu, 7 May 2020 22:36:43 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id z11so807308ybk.2 for ; Thu, 07 May 2020 22:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kf/Nl54LdD1Myd4Q2ihfierbY9Agfscu2MTKHIAamr0=; b=s3XhVoaJuVP7bfI29XP+1KV8iq/zlxEkxZpwETde6utnftcO1DZWav49uNhLe9yLot +5/BdgyKr/VjJ3NqNKoK+eh6gBwyC3Oa7xXwAXVvKgWiZxGCTrBsX0PWDwuZFt0LALxS W88zJ02aK0yyrAQaCPjn2L6BbibphSG3vz7GsueuTLhoYcdhPiz8nEzV/5ntVLYPHUSR Wyy7zFsHLy5pXaIkJvbLXXRvpynpq8+VYRCoy8O1Kppx1y2azcHzoMe6RCGLINLMBrbL fvGBdGFk+cDjvAo7kCUIID/P2Z5ZFqkjEKrZGP8BBeYhQ4u4+ELHUH0kaMTwORFRbnSK SULg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kf/Nl54LdD1Myd4Q2ihfierbY9Agfscu2MTKHIAamr0=; b=INyImggbXA2PE8IXWHPiSXpUdv4EnO4hrQb8Z5K5pTN7zx6fMnn7AzdYSc+QAaItvW 5wZgbheFBU5azM6YM4/Szlfq8qUd/3bnzAhnN+aCuopJNfosqzPeWGAJDC9xPYihEFop gZBMPXNUxTZofDSQWGC4NTRCNgiqty0S5EGqIDJjoxU35EuKTP7mOYCclJm3jDWJmKnC LSvH98WzVJRnt919H1pFD3um1rahmaPVrxJfEtK9Wwg29FKZJVqsivW9fK0jZdB+2VuU QcywNrNGBokNzKd8WXnWyT1Ey8AOyxHsZTKs1gvJihj1GpSwCiId3kiNOWVjQP8mM/e9 WHxw== X-Gm-Message-State: AGi0PuboMW18kGc/lS5vE81d3bzEI2P3G36G6y9UKc+LHMJIrIzMcVR8 qEjSUf09smX/A9jOlXol5TYX4gVPrKRH X-Received: by 2002:a25:cf50:: with SMTP id f77mr1986942ybg.19.1588916202354; Thu, 07 May 2020 22:36:42 -0700 (PDT) Date: Thu, 7 May 2020 22:36:20 -0700 In-Reply-To: <20200508053629.210324-1-irogers@google.com> Message-Id: <20200508053629.210324-6-irogers@google.com> Mime-Version: 1.0 References: <20200508053629.210324-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog Subject: [RFC PATCH v3 05/14] perf expr: fix memory leaks in bison From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , Kajol Jain , Andi Kleen , John Garry , Jin Yao , Kan Liang , Cong Wang , Kim Phillips , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, Vince Weaver , Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a destructor for strings to reclaim memory in the event of errors. Free the ID given for a lookup. Signed-off-by: Ian Rogers --- tools/perf/util/expr.y | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y index 21e82a1e11a2..3b49b230b111 100644 --- a/tools/perf/util/expr.y +++ b/tools/perf/util/expr.y @@ -27,6 +27,7 @@ %token EXPR_PARSE EXPR_OTHER EXPR_ERROR %token NUMBER %token ID +%destructor { free ($$); } %token MIN MAX IF ELSE SMT_ON %left MIN MAX IF %left '|' @@ -94,8 +95,10 @@ if_expr: expr: NUMBER | ID { if (lookup_id(ctx, $1, &$$) < 0) { pr_debug("%s not found\n", $1); + free($1); YYABORT; } + free($1); } | expr '|' expr { $$ = (long)$1 | (long)$3; } | expr '&' expr { $$ = (long)$1 & (long)$3; } -- 2.26.2.645.ge9eca65c58-goog