Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp2140218imc; Fri, 22 Feb 2019 19:19:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IY+7p7ftotpKGmILReJMcK6XnLp659yCdG4/Yi1QFtmdlnii7Q2Pxq9nQLRjw6bVHuXNm4W X-Received: by 2002:a17:902:f096:: with SMTP id go22mr7248827plb.172.1550891976360; Fri, 22 Feb 2019 19:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550891976; cv=none; d=google.com; s=arc-20160816; b=PBC+94Aqoq4AQbqBnGqdK2Yz9E8xJ5iURlRtWcwTkNYpRmqh80ZE9d8x18R/J/XT0v 8LvunbKeAPwl46kDKrPW5dXugGPcQVQWJf9BjyI2uftk8PL4zJ3s/7bX7tetRBy/uOkr hXVAre5cDYhpzwT+KBUrb09V4rx5YGqVgYge91rSIV6q+LVprilxip7NDh6UQNS5nDnL kGlV2tzbNIcZHzZTyGnGpsEEo02gLzDfN8SXhvPAKqsXDKICkPQLrlFrVdWTYioxi1Lw 3zvpBq+FxgurrZaOQP2pfBHKQQMSnFPYoOOuTe2n9jyLnso01hGRUUiJT5ghnoqfoQhm nq7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=aFO+7+oa0wvRqUr3GH29+Yi0Dkk9WdcGMAMbDKLC1jA=; b=PnzM56r9NqEHRmlvhdPTXRbUpNj1L9x/ybUWQ0mVw8D9gamoqzfk4iw5u3kfFdUb4d UUtXyBk096+kny5eivNpUP/y/8v+nzGSQnM9hWRDnafm7Kw6DpYrJQ5Mz48bAqzVOojo FGezk6niJOjd8BvRP8zUqEIRTK3ZCFhGctpS+ml0Jw5Ks77AlekrYkLZg+INv4uMBRn6 lnbvdSWOTqPdwDgqIHeZ9CvVBDjcMVPzc+xIYeBy2OMoAHjHZ2LG8yuXHfOI8balXObe 2MN0KBOTGONsd+x8slrqHrWAJXU6uxyuHRSgUomZKnZQKj12aejClsMnKT0WrQciqTfL 81vQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 r10si2667023pgv.244.2019.02.22.19.19.21; Fri, 22 Feb 2019 19:19:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbfBWDSe (ORCPT + 99 others); Fri, 22 Feb 2019 22:18:34 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:55963 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBWDSc (ORCPT ); Fri, 22 Feb 2019 22:18:32 -0500 Received: by mail-wm1-f68.google.com with SMTP id q187so3595644wme.5; Fri, 22 Feb 2019 19:18:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aFO+7+oa0wvRqUr3GH29+Yi0Dkk9WdcGMAMbDKLC1jA=; b=sVcPLJqsphxrdRPgWqQWrlwLCrLKuS1uYn8X2DkyTHSuiqw/E6yoUED5MTZ5IPGU9i pUskZNLCcFMAMEBhzzbRWBhUIeHrt3Bc9lCrDcJdXnPfT7cbU3x7BIgcyrFcrD1IGgs+ lWlLrdVqJemFxRdx73g7WZYDtG6Iz3IZbquJBy1yCG97ObjjmEC6quzZIEqKjfYyDQjQ M/MBBjOSU7Dwy4RzoOr6hKhsGZ0owsPBT0IOnIUVqTDw55a9Gf2/h/a7izu+7fkiwVCa CnvyMiVn6LRyuy5CDQ90PGEpbb4tRKhNUz0CByhgmae4b5b61UrYAfgXB7ME3CqTu4pX QRnQ== X-Gm-Message-State: AHQUAubyWIbVTMrwvIouvCK9oqIEEXz2eGw1WhBGfMG+gWAq2TBcHtRi BJ23Y30NYj1X5QTPWb48ESHA3hI1WVIUjCiEx9E= X-Received: by 2002:a7b:c752:: with SMTP id w18mr4408299wmk.97.1550891909929; Fri, 22 Feb 2019 19:18:29 -0800 (PST) MIME-Version: 1.0 References: <20190221122306.1511-1-jonas.rabenstein@studium.uni-erlangen.de> <20190221123909.GG10990@krava> <20190221135320.io7egcwajehfrdd5@studium.uni-erlangen.de> <20190221162858.GA3940@krava> In-Reply-To: <20190221162858.GA3940@krava> From: Namhyung Kim Date: Sat, 23 Feb 2019 12:18:18 +0900 Message-ID: Subject: Re: [PATCH] perf hist: fix memory leak if histogram entry is reused To: Jiri Olsa Cc: Jonas Rabenstein , linux-perf-users , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , linux-kernel 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 Hi, On Fri, Feb 22, 2019 at 1:29 AM Jiri Olsa wrote: > > On Thu, Feb 21, 2019 at 02:53:20PM +0100, Jonas Rabenstein wrote: > > On Thu, Feb 21, 2019 at 01:39:09PM +0100, Jiri Olsa wrote: > > > On Thu, Feb 21, 2019 at 01:23:06PM +0100, Jonas Rabenstein wrote: > > > > In __hists__add_entry the srcline of the addr_location is duplicated > > > > for the hist_entry. If hists__findnew_entry returns an already existing > > > > hist_entry the srcline has to be freed again as no further reference to > > > > that duplicated srcline would exists anymore. > > > > > > > > Signed-off-by: Jonas Rabenstein > > > > --- > > > > tools/perf/util/hist.c | 3 +++ > > > > 1 file changed, 3 insertions(+) > > > > > > > > diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c > > > > index 8aad8330e392..25b8dbdbbe87 100644 > > > > --- a/tools/perf/util/hist.c > > > > +++ b/tools/perf/util/hist.c > > > > @@ -623,6 +623,9 @@ __hists__add_entry(struct hists *hists, > > > > .ops = ops, > > > > }, *he = hists__findnew_entry(hists, &entry, al, sample_self); > > > > > > > > + if (he && he->srcline != entry.srcline) > > > > + free(entry.srcline); > > > > + > > > > if (!hists->has_callchains && he && he->callchain_size != 0) > > > > hists->has_callchains = true; > > > > return he; > > > > > > nice, do we have similar issue in here? > > > > > > jirka > > > > > > > > > --- > > > diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c > > > index 216388003dea..e65e6822c848 100644 > > > --- a/tools/perf/util/hist.c > > > +++ b/tools/perf/util/hist.c > > > @@ -966,7 +966,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter, > > > .map = al->map, > > > .sym = al->sym, > > > }, > > > - .srcline = al->srcline ? strdup(al->srcline) : NULL, > > > + .srcline = al->srcline, > > While this shouldn't leak the memory, we may end up with an al->srcline > > to get free afterwards while still having a reference on it within the > > hist_entry... Also I could not find where/how the hist_entry is freed up > > so we may get an double free if both of al and he clean the srcline. > > Of course, with your solution we could spare the useless strdup/free if > > we find an hist_entry (which should be the typical case for hotspots..). > > Taking a deeper look thus should be beneficial - but I do not have the > > time for that right now because I'm still working on the inline-symbol > > integration which is more important for me... > > ok, I'll check it I think we can defer calling strdup() to hist_entry__init(). Thanks, Namhyung