[PATCH v4] memory leak fix while calling system_path

2012-09-17 Thread liang xie
memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments
Since v2: Make system_path_exec_path always return dynamically
allocated string
Since v3: check strdup() per Namhyung's comments

Signed-off-by: xieliang 
---
 tools/perf/builtin-help.c   |   12 +---
 tools/perf/builtin-script.c |   13 ++---
 tools/perf/perf.c   |8 ++--
 tools/perf/util/config.c|   16 +---
 tools/perf/util/exec_cmd.c  |   42 +-
 tools/perf/util/exec_cmd.h  |4 ++--
 tools/perf/util/help.c  |6 --
 7 files changed, 65 insertions(+), 36 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 6d5a8a7..180a5bd 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -321,12 +321,13 @@ static void setup_man_path(void)
 {
struct strbuf new_path = STRBUF_INIT;
const char *old_path = getenv("MANPATH");
+   char *man_path = system_path(PERF_MAN_PATH);

/* We should always put ':' after our path. If there is no
 * old_path, the ':' at the end will let 'man' to try
 * system-wide paths after ours to find the manual page. If
 * there is old_path, we need ':' as delimiter. */
-   strbuf_addstr(_path, system_path(PERF_MAN_PATH));
+   strbuf_addstr(_path, man_path);
strbuf_addch(_path, ':');
if (old_path)
strbuf_addstr(_path, old_path);
@@ -334,6 +335,7 @@ static void setup_man_path(void)
setenv("MANPATH", new_path.buf, 1);

strbuf_release(_path);
+   free(man_path);
 }

 static void exec_viewer(const char *name, const char *page)
@@ -371,14 +373,16 @@ static void show_man_page(const char *perf_cmd)
 static void show_info_page(const char *perf_cmd)
 {
const char *page = cmd_to_page(perf_cmd);
-   setenv("INFOPATH", system_path(PERF_INFO_PATH), 1);
+   char *info_path = system_path(PERF_INFO_PATH);
+   setenv("INFOPATH", info_path, 1);
execlp("info", "info", "perfman", page, NULL);
+   free(info_path);
 }

 static void get_html_page_path(struct strbuf *page_path, const char *page)
 {
struct stat st;
-   const char *html_path = system_path(PERF_HTML_PATH);
+   char *html_path = system_path(PERF_HTML_PATH);

/* Check that we have a perf documentation directory. */
if (stat(mkpath("%s/perf.html", html_path), )
@@ -387,6 +391,7 @@ static void get_html_page_path(struct strbuf
*page_path, const char *page)

strbuf_init(page_path, 0);
strbuf_addf(page_path, "%s/%s.html", html_path, page);
+   free(html_path);
 }

 /*
@@ -409,6 +414,7 @@ static void show_html_page(const char *perf_cmd)
get_html_page_path(_path, page);

open_html(page_path.buf);
+   strbuf_release(_path);
 }

 int cmd_help(int argc, const char **argv, const char *prefix __used)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab7..528b786 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1021,8 +1021,10 @@ static int list_available_scripts(const struct
option *opt __used,
struct script_desc *desc;
char first_half[BUFSIZ];
char *script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1066,8 +1068,10 @@ static char *get_script_path(const char
*script_root, const char *suffix)
DIR *scripts_dir, *lang_dir;
char lang_path[MAXPATHLEN];
char *__script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1199,6 +1203,7 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
 {
char *rec_script_path = NULL;
char *rep_script_path = NULL;
+   char *exec_path = NULL;
struct perf_session *session;
char *script_path = NULL;
const char **__argv;
@@ -1226,7 +1231,9 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
}

/* make sure PERF_EXEC_PATH is set for scripts */
-   perf_set_argv_exec_path(perf_exec_path());
+   exec_path = perf_exec_path();
+   perf_set_argv_exec_path(exec_path);
+   free(exec_path);

if (argc && !script_name && !rec_script_path && !rep_script_path) {
int live_pipe[2];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2b2e225..2198725 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -104,11 +104,15 @@ static int 

[PATCH v4] memory leak fix while calling system_path

2012-09-17 Thread liang xie
memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments
Since v2: Make system_pathperf_exec_path always return dynamically
allocated string
Since v3: check strdup() per Namhyung's comments

Signed-off-by: xieliang xieli...@xiaomi.com
---
 tools/perf/builtin-help.c   |   12 +---
 tools/perf/builtin-script.c |   13 ++---
 tools/perf/perf.c   |8 ++--
 tools/perf/util/config.c|   16 +---
 tools/perf/util/exec_cmd.c  |   42 +-
 tools/perf/util/exec_cmd.h  |4 ++--
 tools/perf/util/help.c  |6 --
 7 files changed, 65 insertions(+), 36 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 6d5a8a7..180a5bd 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -321,12 +321,13 @@ static void setup_man_path(void)
 {
struct strbuf new_path = STRBUF_INIT;
const char *old_path = getenv(MANPATH);
+   char *man_path = system_path(PERF_MAN_PATH);

/* We should always put ':' after our path. If there is no
 * old_path, the ':' at the end will let 'man' to try
 * system-wide paths after ours to find the manual page. If
 * there is old_path, we need ':' as delimiter. */
-   strbuf_addstr(new_path, system_path(PERF_MAN_PATH));
+   strbuf_addstr(new_path, man_path);
strbuf_addch(new_path, ':');
if (old_path)
strbuf_addstr(new_path, old_path);
@@ -334,6 +335,7 @@ static void setup_man_path(void)
setenv(MANPATH, new_path.buf, 1);

strbuf_release(new_path);
+   free(man_path);
 }

 static void exec_viewer(const char *name, const char *page)
@@ -371,14 +373,16 @@ static void show_man_page(const char *perf_cmd)
 static void show_info_page(const char *perf_cmd)
 {
const char *page = cmd_to_page(perf_cmd);
-   setenv(INFOPATH, system_path(PERF_INFO_PATH), 1);
+   char *info_path = system_path(PERF_INFO_PATH);
+   setenv(INFOPATH, info_path, 1);
execlp(info, info, perfman, page, NULL);
+   free(info_path);
 }

 static void get_html_page_path(struct strbuf *page_path, const char *page)
 {
struct stat st;
-   const char *html_path = system_path(PERF_HTML_PATH);
+   char *html_path = system_path(PERF_HTML_PATH);

/* Check that we have a perf documentation directory. */
if (stat(mkpath(%s/perf.html, html_path), st)
@@ -387,6 +391,7 @@ static void get_html_page_path(struct strbuf
*page_path, const char *page)

strbuf_init(page_path, 0);
strbuf_addf(page_path, %s/%s.html, html_path, page);
+   free(html_path);
 }

 /*
@@ -409,6 +414,7 @@ static void show_html_page(const char *perf_cmd)
get_html_page_path(page_path, page);

open_html(page_path.buf);
+   strbuf_release(page_path);
 }

 int cmd_help(int argc, const char **argv, const char *prefix __used)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab7..528b786 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1021,8 +1021,10 @@ static int list_available_scripts(const struct
option *opt __used,
struct script_desc *desc;
char first_half[BUFSIZ];
char *script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, %s/scripts, exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1066,8 +1068,10 @@ static char *get_script_path(const char
*script_root, const char *suffix)
DIR *scripts_dir, *lang_dir;
char lang_path[MAXPATHLEN];
char *__script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, %s/scripts, exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1199,6 +1203,7 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
 {
char *rec_script_path = NULL;
char *rep_script_path = NULL;
+   char *exec_path = NULL;
struct perf_session *session;
char *script_path = NULL;
const char **__argv;
@@ -1226,7 +1231,9 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
}

/* make sure PERF_EXEC_PATH is set for scripts */
-   perf_set_argv_exec_path(perf_exec_path());
+   exec_path = perf_exec_path();
+   perf_set_argv_exec_path(exec_path);
+   free(exec_path);

if (argc  !script_name  !rec_script_path  !rep_script_path) {
int live_pipe[2];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2b2e225..2198725 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -104,11 +104,15 @@ static 

[PATCH v3] memory leak fix while calling system_path

2012-09-13 Thread liang xie
memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments
Since v2: Make system_path_exec_path always return dynamically
allocated string

Signed-off-by: xieliang 
---
 tools/perf/builtin-help.c   |   12 +---
 tools/perf/builtin-script.c |   13 ++---
 tools/perf/perf.c   |8 ++--
 tools/perf/util/config.c|   16 +---
 tools/perf/util/exec_cmd.c  |   26 +++---
 tools/perf/util/exec_cmd.h  |4 ++--
 tools/perf/util/help.c  |6 --
 7 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 6d5a8a7..180a5bd 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -321,12 +321,13 @@ static void setup_man_path(void)
 {
struct strbuf new_path = STRBUF_INIT;
const char *old_path = getenv("MANPATH");
+   char *man_path = system_path(PERF_MAN_PATH);

/* We should always put ':' after our path. If there is no
 * old_path, the ':' at the end will let 'man' to try
 * system-wide paths after ours to find the manual page. If
 * there is old_path, we need ':' as delimiter. */
-   strbuf_addstr(_path, system_path(PERF_MAN_PATH));
+   strbuf_addstr(_path, man_path);
strbuf_addch(_path, ':');
if (old_path)
strbuf_addstr(_path, old_path);
@@ -334,6 +335,7 @@ static void setup_man_path(void)
setenv("MANPATH", new_path.buf, 1);

strbuf_release(_path);
+   free(man_path);
 }

 static void exec_viewer(const char *name, const char *page)
@@ -371,14 +373,16 @@ static void show_man_page(const char *perf_cmd)
 static void show_info_page(const char *perf_cmd)
 {
const char *page = cmd_to_page(perf_cmd);
-   setenv("INFOPATH", system_path(PERF_INFO_PATH), 1);
+   char *info_path = system_path(PERF_INFO_PATH);
+   setenv("INFOPATH", info_path, 1);
execlp("info", "info", "perfman", page, NULL);
+   free(info_path);
 }

 static void get_html_page_path(struct strbuf *page_path, const char *page)
 {
struct stat st;
-   const char *html_path = system_path(PERF_HTML_PATH);
+   char *html_path = system_path(PERF_HTML_PATH);

/* Check that we have a perf documentation directory. */
if (stat(mkpath("%s/perf.html", html_path), )
@@ -387,6 +391,7 @@ static void get_html_page_path(struct strbuf
*page_path, const char *page)

strbuf_init(page_path, 0);
strbuf_addf(page_path, "%s/%s.html", html_path, page);
+   free(html_path);
 }

 /*
@@ -409,6 +414,7 @@ static void show_html_page(const char *perf_cmd)
get_html_page_path(_path, page);

open_html(page_path.buf);
+   strbuf_release(_path);
 }

 int cmd_help(int argc, const char **argv, const char *prefix __used)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab7..528b786 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1021,8 +1021,10 @@ static int list_available_scripts(const struct
option *opt __used,
struct script_desc *desc;
char first_half[BUFSIZ];
char *script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1066,8 +1068,10 @@ static char *get_script_path(const char
*script_root, const char *suffix)
DIR *scripts_dir, *lang_dir;
char lang_path[MAXPATHLEN];
char *__script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, "%s/scripts", exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1199,6 +1203,7 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
 {
char *rec_script_path = NULL;
char *rep_script_path = NULL;
+   char *exec_path = NULL;
struct perf_session *session;
char *script_path = NULL;
const char **__argv;
@@ -1226,7 +1231,9 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
}

/* make sure PERF_EXEC_PATH is set for scripts */
-   perf_set_argv_exec_path(perf_exec_path());
+   exec_path = perf_exec_path();
+   perf_set_argv_exec_path(exec_path);
+   free(exec_path);

if (argc && !script_name && !rec_script_path && !rep_script_path) {
int live_pipe[2];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2b2e225..2198725 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -104,11 +104,15 @@ static int handle_options(const char ***argv,
int *argc, int *envchanged)
  

[PATCH v3] memory leak fix while calling system_path

2012-09-13 Thread liang xie
memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments
Since v2: Make system_pathperf_exec_path always return dynamically
allocated string

Signed-off-by: xieliang xieli...@xiaomi.com
---
 tools/perf/builtin-help.c   |   12 +---
 tools/perf/builtin-script.c |   13 ++---
 tools/perf/perf.c   |8 ++--
 tools/perf/util/config.c|   16 +---
 tools/perf/util/exec_cmd.c  |   26 +++---
 tools/perf/util/exec_cmd.h  |4 ++--
 tools/perf/util/help.c  |6 --
 7 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 6d5a8a7..180a5bd 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -321,12 +321,13 @@ static void setup_man_path(void)
 {
struct strbuf new_path = STRBUF_INIT;
const char *old_path = getenv(MANPATH);
+   char *man_path = system_path(PERF_MAN_PATH);

/* We should always put ':' after our path. If there is no
 * old_path, the ':' at the end will let 'man' to try
 * system-wide paths after ours to find the manual page. If
 * there is old_path, we need ':' as delimiter. */
-   strbuf_addstr(new_path, system_path(PERF_MAN_PATH));
+   strbuf_addstr(new_path, man_path);
strbuf_addch(new_path, ':');
if (old_path)
strbuf_addstr(new_path, old_path);
@@ -334,6 +335,7 @@ static void setup_man_path(void)
setenv(MANPATH, new_path.buf, 1);

strbuf_release(new_path);
+   free(man_path);
 }

 static void exec_viewer(const char *name, const char *page)
@@ -371,14 +373,16 @@ static void show_man_page(const char *perf_cmd)
 static void show_info_page(const char *perf_cmd)
 {
const char *page = cmd_to_page(perf_cmd);
-   setenv(INFOPATH, system_path(PERF_INFO_PATH), 1);
+   char *info_path = system_path(PERF_INFO_PATH);
+   setenv(INFOPATH, info_path, 1);
execlp(info, info, perfman, page, NULL);
+   free(info_path);
 }

 static void get_html_page_path(struct strbuf *page_path, const char *page)
 {
struct stat st;
-   const char *html_path = system_path(PERF_HTML_PATH);
+   char *html_path = system_path(PERF_HTML_PATH);

/* Check that we have a perf documentation directory. */
if (stat(mkpath(%s/perf.html, html_path), st)
@@ -387,6 +391,7 @@ static void get_html_page_path(struct strbuf
*page_path, const char *page)

strbuf_init(page_path, 0);
strbuf_addf(page_path, %s/%s.html, html_path, page);
+   free(html_path);
 }

 /*
@@ -409,6 +414,7 @@ static void show_html_page(const char *perf_cmd)
get_html_page_path(page_path, page);

open_html(page_path.buf);
+   strbuf_release(page_path);
 }

 int cmd_help(int argc, const char **argv, const char *prefix __used)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 1e60ab7..528b786 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1021,8 +1021,10 @@ static int list_available_scripts(const struct
option *opt __used,
struct script_desc *desc;
char first_half[BUFSIZ];
char *script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, %s/scripts, exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1066,8 +1068,10 @@ static char *get_script_path(const char
*script_root, const char *suffix)
DIR *scripts_dir, *lang_dir;
char lang_path[MAXPATHLEN];
char *__script_root;
+   char *exec_path = perf_exec_path();

-   snprintf(scripts_path, MAXPATHLEN, %s/scripts, perf_exec_path());
+   snprintf(scripts_path, MAXPATHLEN, %s/scripts, exec_path);
+   free(exec_path);

scripts_dir = opendir(scripts_path);
if (!scripts_dir)
@@ -1199,6 +1203,7 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
 {
char *rec_script_path = NULL;
char *rep_script_path = NULL;
+   char *exec_path = NULL;
struct perf_session *session;
char *script_path = NULL;
const char **__argv;
@@ -1226,7 +1231,9 @@ int cmd_script(int argc, const char **argv,
const char *prefix __used)
}

/* make sure PERF_EXEC_PATH is set for scripts */
-   perf_set_argv_exec_path(perf_exec_path());
+   exec_path = perf_exec_path();
+   perf_set_argv_exec_path(exec_path);
+   free(exec_path);

if (argc  !script_name  !rec_script_path  !rep_script_path) {
int live_pipe[2];
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2b2e225..2198725 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -104,11 +104,15 @@ static int handle_options(const char ***argv,
int *argc, int 

[PATCH v2] A trivial memory leak fix while calling system_path

2012-09-06 Thread liang xie
A trivial memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments

Signed-off-by: Liang Xie 
---
 tools/perf/util/exec_cmd.c |4 +++-
 tools/perf/util/help.c |1 +
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad..d041407 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -83,8 +83,9 @@ void setup_path(void)
 {
const char *old_path = getenv("PATH");
struct strbuf new_path = STRBUF_INIT;
+   const char *exec_path = perf_exec_path();

-   add_path(_path, perf_exec_path());
+   add_path(_path, exec_path);
add_path(_path, argv0_path);

if (old_path)
@@ -95,6 +96,7 @@ void setup_path(void)
setenv("PATH", new_path.buf, 1);

strbuf_release(_path);
+   free((void *)exec_path);
 }

 static const char **prepare_perf_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6f2975a..798f66d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
uniq(other_cmds);
}
exclude_cmds(other_cmds, main_cmds);
+   free((void *)exec_path);
 }

 void list_commands(const char *title, struct cmdnames *main_cmds,
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] A trivial memory leak fix while calling system_path

2012-09-06 Thread liang xie
A trivial memory leak fix while calling system_path

Since v1: Remove an unnecessary null pointer check per Felipe's comments

Signed-off-by: Liang Xie xieli...@xiaomi.com
---
 tools/perf/util/exec_cmd.c |4 +++-
 tools/perf/util/help.c |1 +
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad..d041407 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -83,8 +83,9 @@ void setup_path(void)
 {
const char *old_path = getenv(PATH);
struct strbuf new_path = STRBUF_INIT;
+   const char *exec_path = perf_exec_path();

-   add_path(new_path, perf_exec_path());
+   add_path(new_path, exec_path);
add_path(new_path, argv0_path);

if (old_path)
@@ -95,6 +96,7 @@ void setup_path(void)
setenv(PATH, new_path.buf, 1);

strbuf_release(new_path);
+   free((void *)exec_path);
 }

 static const char **prepare_perf_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6f2975a..798f66d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
uniq(other_cmds);
}
exclude_cmds(other_cmds, main_cmds);
+   free((void *)exec_path);
 }

 void list_commands(const char *title, struct cmdnames *main_cmds,
-- 
1.7.1
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] perf tool: fix trivial memory leak while calling system_path()

2012-09-05 Thread liang xie
Hi Felipe,

Thanks for reviewing! yeh, the check could be removed safely .
For casting, it'll complain like this if removed:
cc1: warnings being treated as errors
util/help.c: In function ‘load_command_list’:
util/help.c:190: error: passing argument 1 of ‘free’ discards
qualifiers from pointer target type
/usr/include/stdlib.h:488: note: expected ‘void *’ but argument is of
type ‘const char *’
make: *** [util/help.o] Error 1

Best Regards,

On Wed, Sep 5, 2012 at 9:49 PM, Felipe Balbi  wrote:
> Hi,
>
> On Wed, Sep 05, 2012 at 09:48:54PM +0800, liang xie wrote:
>> A trivial memory leak fix while calling system_path
>>
>> Signed-off-by: Liang Xie 
>> ---
>>  tools/perf/util/exec_cmd.c |6 --
>>  tools/perf/util/help.c |1 +
>>  2 files changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
>> index 7adf4ad..790cc95 100644
>> --- a/tools/perf/util/exec_cmd.c
>> +++ b/tools/perf/util/exec_cmd.c
>> @@ -83,8 +83,8 @@ void setup_path(void)
>>  {
>>   const char *old_path = getenv("PATH");
>>   struct strbuf new_path = STRBUF_INIT;
>> -
>> - add_path(_path, perf_exec_path());
>> + const char *exec_path = perf_exec_path();
>> + add_path(_path, exec_path);
>>   add_path(_path, argv0_path);
>>
>>   if (old_path)
>> @@ -95,6 +95,8 @@ void setup_path(void)
>>   setenv("PATH", new_path.buf, 1);
>>
>>   strbuf_release(_path);
>> + if (exec_path)
>
> free(NULL) is safe, the check isn't needed.
>
>> + free((void *)exec_path);
>
> this cast doesn't look necessary either.
>
> --
> balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] perf tool: fix trivial memory leak while calling system_path()

2012-09-05 Thread liang xie
A trivial memory leak fix while calling system_path

Signed-off-by: Liang Xie 
---
 tools/perf/util/exec_cmd.c |6 --
 tools/perf/util/help.c |1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad..790cc95 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -83,8 +83,8 @@ void setup_path(void)
 {
const char *old_path = getenv("PATH");
struct strbuf new_path = STRBUF_INIT;
-
-   add_path(_path, perf_exec_path());
+   const char *exec_path = perf_exec_path();
+   add_path(_path, exec_path);
add_path(_path, argv0_path);

if (old_path)
@@ -95,6 +95,8 @@ void setup_path(void)
setenv("PATH", new_path.buf, 1);

strbuf_release(_path);
+   if (exec_path)
+   free((void *)exec_path);
 }

 static const char **prepare_perf_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6f2975a..798f66d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
uniq(other_cmds);
}
exclude_cmds(other_cmds, main_cmds);
+   free((void *)exec_path);
 }

 void list_commands(const char *title, struct cmdnames *main_cmds,
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] perf tool: fix trivial memory leak while calling system_path()

2012-09-05 Thread liang xie
A trivial memory leak fix while calling system_path

Signed-off-by: Liang Xie xieli...@xiaomi.com
---
 tools/perf/util/exec_cmd.c |6 --
 tools/perf/util/help.c |1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index 7adf4ad..790cc95 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -83,8 +83,8 @@ void setup_path(void)
 {
const char *old_path = getenv(PATH);
struct strbuf new_path = STRBUF_INIT;
-
-   add_path(new_path, perf_exec_path());
+   const char *exec_path = perf_exec_path();
+   add_path(new_path, exec_path);
add_path(new_path, argv0_path);

if (old_path)
@@ -95,6 +95,8 @@ void setup_path(void)
setenv(PATH, new_path.buf, 1);

strbuf_release(new_path);
+   if (exec_path)
+   free((void *)exec_path);
 }

 static const char **prepare_perf_cmd(const char **argv)
diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
index 6f2975a..798f66d 100644
--- a/tools/perf/util/help.c
+++ b/tools/perf/util/help.c
@@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
uniq(other_cmds);
}
exclude_cmds(other_cmds, main_cmds);
+   free((void *)exec_path);
 }

 void list_commands(const char *title, struct cmdnames *main_cmds,
-- 
1.7.1
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] perf tool: fix trivial memory leak while calling system_path()

2012-09-05 Thread liang xie
Hi Felipe,

Thanks for reviewing! yeh, the check could be removed safely .
For casting, it'll complain like this if removed:
cc1: warnings being treated as errors
util/help.c: In function ‘load_command_list’:
util/help.c:190: error: passing argument 1 of ‘free’ discards
qualifiers from pointer target type
/usr/include/stdlib.h:488: note: expected ‘void *’ but argument is of
type ‘const char *’
make: *** [util/help.o] Error 1

Best Regards,

On Wed, Sep 5, 2012 at 9:49 PM, Felipe Balbi ba...@ti.com wrote:
 Hi,

 On Wed, Sep 05, 2012 at 09:48:54PM +0800, liang xie wrote:
 A trivial memory leak fix while calling system_path

 Signed-off-by: Liang Xie xieli...@xiaomi.com
 ---
  tools/perf/util/exec_cmd.c |6 --
  tools/perf/util/help.c |1 +
  2 files changed, 5 insertions(+), 2 deletions(-)

 diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
 index 7adf4ad..790cc95 100644
 --- a/tools/perf/util/exec_cmd.c
 +++ b/tools/perf/util/exec_cmd.c
 @@ -83,8 +83,8 @@ void setup_path(void)
  {
   const char *old_path = getenv(PATH);
   struct strbuf new_path = STRBUF_INIT;
 -
 - add_path(new_path, perf_exec_path());
 + const char *exec_path = perf_exec_path();
 + add_path(new_path, exec_path);
   add_path(new_path, argv0_path);

   if (old_path)
 @@ -95,6 +95,8 @@ void setup_path(void)
   setenv(PATH, new_path.buf, 1);

   strbuf_release(new_path);
 + if (exec_path)

 free(NULL) is safe, the check isn't needed.

 + free((void *)exec_path);

 this cast doesn't look necessary either.

 --
 balbi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/1] Document:add Chinese translation of basic_profiling.txt

2012-08-26 Thread liang xie
This is a Chinese translated version of Documentation/basic_profiling.txt

Signed-off-by: Liang Xie 
---
 Documentation/zh_CN/basic_profiling.txt |   71 +++
 1 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100755 Documentation/zh_CN/basic_profiling.txt

diff --git a/Documentation/zh_CN/basic_profiling.txt
b/Documentation/zh_CN/basic_profiling.txt
new file mode 100755
index 000..3105eaf
--- /dev/null
+++ b/Documentation/zh_CN/basic_profiling.txt
@@ -0,0 +1,71 @@
+Chinese translated version of Documentation/basic_profiling
+
+If you have any comment or update to the content, please post to LKML directly.
+However, if you have problem communicating in English you can also ask the
+Chinese maintainer for help.  Contact the Chinese maintainer, if this
+translation is outdated or there is problem with translation.
+
+Chinese maintainer: Liang Xie 
+-
+Documentation/basic_profiling的中文翻译
+
+如果想评论或更新本文的内容,请直接发信到LKML。如果你使用英文交流有困难的话,也可
+以向中文版维护者求助。如果本翻译更新不及时或者翻译存在问题,请联系中文版维护者。
+
+中文版维护者: 谢良 Liang Xie 
+中文版翻译者: 谢良 Liang Xie 
+中文版校译者:
+以下为正文
+-
+
+下面这些说明指令都是非常基础的,如果你想进一步了解请阅读相关专业文档:)
+请不要再在本文档增加新的内容,但可以修复文档中的错误:)(mbl...@aracnet.com)
+感谢John Levon,Dave Hansen等在撰写时的帮助
+
+ 用于表示要测量的目标
+请先确保您已经有正确的System.map / vmlinux配置!
+
+对于linux系统来说,配置vmlinuz最容易的方法可能就是使用“make install”,然后修改
+/sbin/installkernel将vmlinux拷贝到/boot目录,而System.map通常是默认安装好的
+
+Readprofile
+---
+2.6系列内核需要版本相对较新的readprofile,比如util-linux 2.12a中包含的,可以从:
+
+http://www.kernel.org/pub/linux/utils/util-linux/ 下载
+
+大部分linux发行版已经包含了.
+
+启用readprofile需要在kernel启动命令行增加”profile=2“
+
+clear  readprofile -r
+   
+dump outputreadprofile -m /boot/System.map > captured_profile
+
+Oprofile
+
+
+从http://oprofile.sourceforge.net/获取源代码(请参考Changes以获取匹配的版本)
+在kernel启动命令行增加“idle=poll”
+
+配置CONFIG_PROFILING=y和CONFIG_OPROFILE=y然后重启进入新kernel
+
+./configure --with-kernel-support
+make install
+
+想得到好的测量结果,请确保启用了本地APIC特性。如果opreport显示有0Hz CPU,
+说明APIC特性没有开启。另外注意idle=poll选项可能有损性能。
+
+One time setup:
+   opcontrol --setup --vmlinux=/boot/vmlinux
+
+clear  opcontrol --reset
+start  opcontrol --start
+   
+stop   opcontrol --stop
+dump outputopreport >  output_file
+
+如果只看kernel相关的报告结果,请运行命令 opreport -l /boot/vmlinux > output_file
+
+通过reset选项可以清理过期统计数据,相当于重启的效果。
+
-- 
1.7.9.6 (Apple Git-31.1)


[PATCH 1/1] Document:add Chinese translation of basic_profiling.txt

2012-08-26 Thread liang xie
This is a Chinese translated version of Documentation/basic_profiling.txt

Signed-off-by: Liang Xie xieliang...@gmail.com
---
 Documentation/zh_CN/basic_profiling.txt |   71 +++
 1 files changed, 71 insertions(+), 0 deletions(-)
 create mode 100755 Documentation/zh_CN/basic_profiling.txt

diff --git a/Documentation/zh_CN/basic_profiling.txt
b/Documentation/zh_CN/basic_profiling.txt
new file mode 100755
index 000..3105eaf
--- /dev/null
+++ b/Documentation/zh_CN/basic_profiling.txt
@@ -0,0 +1,71 @@
+Chinese translated version of Documentation/basic_profiling
+
+If you have any comment or update to the content, please post to LKML directly.
+However, if you have problem communicating in English you can also ask the
+Chinese maintainer for help.  Contact the Chinese maintainer, if this
+translation is outdated or there is problem with translation.
+
+Chinese maintainer: Liang Xie xieli...@xiaomi.com
+-
+Documentation/basic_profiling的中文翻译
+
+如果想评论或更新本文的内容,请直接发信到LKML。如果你使用英文交流有困难的话,也可
+以向中文版维护者求助。如果本翻译更新不及时或者翻译存在问题,请联系中文版维护者。
+
+中文版维护者: 谢良 Liang Xie xieliang...@gmail.com
+中文版翻译者: 谢良 Liang Xie xieliang...@gmail.com
+中文版校译者:
+以下为正文
+-
+
+下面这些说明指令都是非常基础的,如果你想进一步了解请阅读相关专业文档:)
+请不要再在本文档增加新的内容,但可以修复文档中的错误:)(mbl...@aracnet.com)
+感谢John Levon,Dave Hansen等在撰写时的帮助
+
+test 用于表示要测量的目标
+请先确保您已经有正确的System.map / vmlinux配置!
+
+对于linux系统来说,配置vmlinuz最容易的方法可能就是使用“make install”,然后修改
+/sbin/installkernel将vmlinux拷贝到/boot目录,而System.map通常是默认安装好的
+
+Readprofile
+---
+2.6系列内核需要版本相对较新的readprofile,比如util-linux 2.12a中包含的,可以从:
+
+http://www.kernel.org/pub/linux/utils/util-linux/ 下载
+
+大部分linux发行版已经包含了.
+
+启用readprofile需要在kernel启动命令行增加”profile=2“
+
+clear  readprofile -r
+   test
+dump outputreadprofile -m /boot/System.map  captured_profile
+
+Oprofile
+
+
+从http://oprofile.sourceforge.net/获取源代码(请参考Changes以获取匹配的版本)
+在kernel启动命令行增加“idle=poll”
+
+配置CONFIG_PROFILING=y和CONFIG_OPROFILE=y然后重启进入新kernel
+
+./configure --with-kernel-support
+make install
+
+想得到好的测量结果,请确保启用了本地APIC特性。如果opreport显示有0Hz CPU,
+说明APIC特性没有开启。另外注意idle=poll选项可能有损性能。
+
+One time setup:
+   opcontrol --setup --vmlinux=/boot/vmlinux
+
+clear  opcontrol --reset
+start  opcontrol --start
+   test
+stop   opcontrol --stop
+dump outputopreport   output_file
+
+如果只看kernel相关的报告结果,请运行命令 opreport -l /boot/vmlinux  output_file
+
+通过reset选项可以清理过期统计数据,相当于重启的效果。
+
-- 
1.7.9.6 (Apple Git-31.1)