Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1415928 > unrolled thread

[BUGFIX][PATCH v7 1/7] perf config: If collect_config() is failed, finally free a config set after it is done

Started byTaeung Song <treeze.taeung@gmail.com>
First post2016-06-07 11:30 +0200
Last post2016-06-08 10:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [BUGFIX][PATCH v7 1/7] perf config: If collect_config() is failed, finally free a config set after it is done Taeung Song <treeze.taeung@gmail.com> - 2016-06-07 11:30 +0200
    [tip:perf/core] perf config: Constructor should free its allocated  memory when failing tip-bot for Taeung Song <tipbot@zytor.com> - 2016-06-08 10:50 +0200

#1415928 — [BUGFIX][PATCH v7 1/7] perf config: If collect_config() is failed, finally free a config set after it is done

FromTaeung Song <treeze.taeung@gmail.com>
Date2016-06-07 11:30 +0200
Subject[BUGFIX][PATCH v7 1/7] perf config: If collect_config() is failed, finally free a config set after it is done
Message-ID<rHluH-Te-51@gated-at.bofh.it>
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 <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/util/config.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index c73f1c4..e086f59 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -643,7 +643,6 @@ static int collect_config(const char *var, const char *value,
 
 out_free:
 	free(key);
-	perf_config_set__delete(set);
 	return -1;
 }
 
@@ -653,7 +652,10 @@ 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);
+			set = NULL;
+		}
 	}
 
 	return set;
-- 
2.5.0

[toc] | [next] | [standalone]


#1417073 — [tip:perf/core] perf config: Constructor should free its allocated memory when failing

Fromtip-bot for Taeung Song <tipbot@zytor.com>
Date2016-06-08 10:50 +0200
Subject[tip:perf/core] perf config: Constructor should free its allocated memory when failing
Message-ID<rHHlv-6ig-15@gated-at.bofh.it>
In reply to#1415928
Commit-ID:  25d8f48f78f37dd6af08bd11212ab3d53a4c8cc6
Gitweb:     http://git.kernel.org/tip/25d8f48f78f37dd6af08bd11212ab3d53a4c8cc6
Author:     Taeung Song <treeze.taeung@gmail.com>
AuthorDate: Tue, 7 Jun 2016 18:26:11 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 7 Jun 2016 10:58:55 -0300

perf config: Constructor should free its allocated memory when failing

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().

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1465291577-20973-2-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/config.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index c73f1c4..e086f59 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -643,7 +643,6 @@ static int collect_config(const char *var, const char *value,
 
 out_free:
 	free(key);
-	perf_config_set__delete(set);
 	return -1;
 }
 
@@ -653,7 +652,10 @@ 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);
+			set = NULL;
+		}
 	}
 
 	return set;

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web