From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752506AbcFFUYB (ORCPT ); Mon, 6 Jun 2016 16:24:01 -0400 Received: from mail.kernel.org ([198.145.29.136]:44665 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751245AbcFFUYA (ORCPT ); Mon, 6 Jun 2016 16:24:00 -0400 Date: Mon, 6 Jun 2016 17:23:55 -0300 From: Arnaldo Carvalho de Melo To: Taeung Song Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim , Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Masami Hiramatsu , Jiri Olsa Subject: Re: [BUGFIX][PATCH v6 2/9] perf config: If collect_config() is failed, finally free a config set after it is done Message-ID: <20160606202355.GB15108@kernel.org> References: <1465210380-26749-1-git-send-email-treeze.taeung@gmail.com> <1465210380-26749-3-git-send-email-treeze.taeung@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1465210380-26749-3-git-send-email-treeze.taeung@gmail.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Mon, Jun 06, 2016 at 07:52:53PM +0900, Taeung Song escreveu: > Because of die() at perf_parse_file() a config set was freed > in collect_config(), if failed. > But it is natural to free a config set after collect_config() is done > when some problems happened. > > So, in case of failure, lastly free a config set at perf_config_set__new() > instead of freeing the config set in collect_config(). > > Cc: Namhyung Kim > Cc: Jiri Olsa > Cc: Masami Hiramatsu > Cc: Alexander Shishkin > Signed-off-by: Taeung Song > --- > tools/perf/util/config.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c > index b500737..d013f90 100644 > --- a/tools/perf/util/config.c > +++ b/tools/perf/util/config.c > @@ -639,7 +639,6 @@ static int collect_config(const char *var, const char *value, > > out_free: > free(key); > - perf_config_set__delete(set); > return -1; > } > > @@ -649,7 +648,8 @@ struct perf_config_set *perf_config_set__new(void) > > if (set) { > INIT_LIST_HEAD(&set->sections); > - perf_config(collect_config, set); > + if (perf_config(collect_config, set) < 0) > + perf_config_set__delete(set); > } > > return set; You can't do that, there is something missing, without looking at the code I think you need: if (set) { INIT_LIST_HEAD(&set->sections); - perf_config(collect_config, set); + if (perf_config(collect_config, set) < 0) { + perf_config_set__delete(set); + set = NULL; + } } return set; No? - Arnaldo