* [PATCH 1/2] perf: add close()/closedir() calls when needed
@ 2010-01-07 16:40 Alexander Beregalov
2010-01-07 16:40 ` [PATCH 2/2] perf: fix memory leak: counterwidth Alexander Beregalov
2010-01-07 21:29 ` [PATCH 1/2] perf: add close()/closedir() calls when needed Paul Mackerras
0 siblings, 2 replies; 6+ messages in thread
From: Alexander Beregalov @ 2010-01-07 16:40 UTC (permalink / raw)
To: a.p.zijlstra, paulus, mingo; +Cc: linux-kernel, Alexander Beregalov
Close file and directory descriptors before exiting or dying.
Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com>
---
tools/perf/builtin-kmem.c | 2 ++
tools/perf/builtin-trace.c | 6 +++++-
tools/perf/util/parse-events.c | 1 +
tools/perf/util/symbol.c | 1 +
tools/perf/util/trace-event-info.c | 20 +++++++++++++++++---
5 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 7ceb741..81735d2 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -112,7 +112,9 @@ static void setup_cpunode_map(void)
continue;
cpunode_map[cpu] = mem;
}
+ closedir(dir2);
}
+ closedir(dir1);
}
static void insert_alloc_stat(unsigned long call_site, unsigned long ptr,
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 574a215..5ad93e2 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -507,7 +507,9 @@ static char *get_script_path(const char *script_root, const char *suffix)
}
free(__script_root);
}
+ closedir(lang_dir);
}
+ closedir(scripts_dir);
return path;
}
@@ -615,7 +617,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
scripting_ops = script_spec__lookup(generate_script_lang);
if (!scripting_ops) {
fprintf(stderr, "invalid language specifier");
- return -1;
+ err = -1;
+ goto out;
}
perf_header__read(&session->header, input);
@@ -634,5 +637,6 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
perf_session__delete(session);
cleanup_scripting();
out:
+ close(input);
return err;
}
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index e5bc0fb..7739a37 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -483,6 +483,7 @@ parse_subsystem_tracepoint_event(char *sys_name, char *flags)
if (parse_events(NULL, event_opt, 0))
return EVT_FAILED;
}
+ closedir(evt_dir);
return EVT_HANDLED_ALL;
}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index ab92763..953e654 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1364,6 +1364,7 @@ static int perf_session__set_modules_path_dir(struct perf_session *self, char *d
}
}
+ closedir(dir);
return 0;
failure:
closedir(dir);
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index cace355..e191126 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -275,6 +275,7 @@ static void read_header_files(void)
die("wrong size for '%s' size=%lld read=%lld",
path, size, check_size);
put_tracing_file(path);
+ close(fd);
path = get_tracing_file("events/header_event");
fd = open(path, O_RDONLY);
@@ -289,6 +290,7 @@ static void read_header_files(void)
if (size != check_size)
die("wrong size for '%s'", path);
put_tracing_file(path);
+ close(fd);
}
static bool name_in_tp_list(char *sys, struct tracepoint_path *tps)
@@ -321,7 +323,11 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
strcmp(dent->d_name, "..") == 0 ||
!name_in_tp_list(dent->d_name, tps))
continue;
- format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
+ format = malloc(strlen(sys) + strlen(dent->d_name) + 10);
+ if (!format) {
+ closedir(dir);
+ die("malloc");
+ }
sprintf(format, "%s/%s/format", sys, dent->d_name);
ret = stat(format, &st);
free(format);
@@ -338,7 +344,11 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
strcmp(dent->d_name, "..") == 0 ||
!name_in_tp_list(dent->d_name, tps))
continue;
- format = malloc_or_die(strlen(sys) + strlen(dent->d_name) + 10);
+ format = malloc(strlen(sys) + strlen(dent->d_name) + 10);
+ if (!format) {
+ closedir(dir);
+ die("malloc");
+ }
sprintf(format, "%s/%s/format", sys, dent->d_name);
ret = stat(format, &st);
@@ -347,12 +357,15 @@ static void copy_event_system(const char *sys, struct tracepoint_path *tps)
size = get_size(format);
write_or_die(&size, 8);
check_size = copy_file(format);
- if (size != check_size)
+ if (size != check_size) {
+ closedir(dir);
die("error in size of file '%s'", format);
+ }
}
free(format);
}
+ closedir(dir);
}
static void read_ftrace_files(struct tracepoint_path *tps)
@@ -429,6 +442,7 @@ static void read_event_files(struct tracepoint_path *tps)
}
free(sys);
}
+ closedir(dir);
put_tracing_file(path);
}
--
1.6.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] perf: fix memory leak: counterwidth
2010-01-07 16:40 [PATCH 1/2] perf: add close()/closedir() calls when needed Alexander Beregalov
@ 2010-01-07 16:40 ` Alexander Beregalov
2010-01-13 10:35 ` [tip:perf/core] perf: Fix " tip-bot for Alexander Beregalov
2010-01-07 21:29 ` [PATCH 1/2] perf: add close()/closedir() calls when needed Paul Mackerras
1 sibling, 1 reply; 6+ messages in thread
From: Alexander Beregalov @ 2010-01-07 16:40 UTC (permalink / raw)
To: a.p.zijlstra, paulus, mingo; +Cc: linux-kernel, Alexander Beregalov
Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com>
---
tools/perf/util/values.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 1c15e39..cfa55d6 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -169,6 +169,7 @@ static void perf_read_values__display_pretty(FILE *fp,
counterwidth[j], values->value[i][j]);
fprintf(fp, "\n");
}
+ free(counterwidth);
}
static void perf_read_values__display_raw(FILE *fp,
--
1.6.6
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf: add close()/closedir() calls when needed
2010-01-07 16:40 [PATCH 1/2] perf: add close()/closedir() calls when needed Alexander Beregalov
2010-01-07 16:40 ` [PATCH 2/2] perf: fix memory leak: counterwidth Alexander Beregalov
@ 2010-01-07 21:29 ` Paul Mackerras
2010-01-07 22:44 ` Alexander Beregalov
1 sibling, 1 reply; 6+ messages in thread
From: Paul Mackerras @ 2010-01-07 21:29 UTC (permalink / raw)
Cc: a.p.zijlstra, mingo, linux-kernel
On Thu, Jan 07, 2010 at 07:40:46PM +0300, Alexander Beregalov wrote:
> Close file and directory descriptors before exiting or dying.
Your patch description doesn't say why that's a good thing to do, and
it's not obvious to me at least. Please explain the motivation in
your patch description.
Paul.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf: add close()/closedir() calls when needed
2010-01-07 21:29 ` [PATCH 1/2] perf: add close()/closedir() calls when needed Paul Mackerras
@ 2010-01-07 22:44 ` Alexander Beregalov
2010-01-07 23:54 ` H. Peter Anvin
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Beregalov @ 2010-01-07 22:44 UTC (permalink / raw)
To: Paul Mackerras; +Cc: a.p.zijlstra, mingo, linux-kernel
2010/1/8 Paul Mackerras <paulus@samba.org>:
> On Thu, Jan 07, 2010 at 07:40:46PM +0300, Alexander Beregalov wrote:
>
>> Close file and directory descriptors before exiting or dying.
>
> Your patch description doesn't say why that's a good thing to do, and
> it's not obvious to me at least. Please explain the motivation in
> your patch description.
Isn't it a good style to close files after use and before exit?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] perf: add close()/closedir() calls when needed
2010-01-07 22:44 ` Alexander Beregalov
@ 2010-01-07 23:54 ` H. Peter Anvin
0 siblings, 0 replies; 6+ messages in thread
From: H. Peter Anvin @ 2010-01-07 23:54 UTC (permalink / raw)
To: Alexander Beregalov; +Cc: Paul Mackerras, a.p.zijlstra, mingo, linux-kernel
On 01/07/2010 02:44 PM, Alexander Beregalov wrote:
> 2010/1/8 Paul Mackerras <paulus@samba.org>:
>> On Thu, Jan 07, 2010 at 07:40:46PM +0300, Alexander Beregalov wrote:
>>
>>> Close file and directory descriptors before exiting or dying.
>>
>> Your patch description doesn't say why that's a good thing to do, and
>> it's not obvious to me at least. Please explain the motivation in
>> your patch description.
>
> Isn't it a good style to close files after use and before exit?
exit() closes all files, so it's redundant.
It's "good style" in the sense that it can help librarization, though.
-hpa
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip:perf/core] perf: Fix memory leak: counterwidth
2010-01-07 16:40 ` [PATCH 2/2] perf: fix memory leak: counterwidth Alexander Beregalov
@ 2010-01-13 10:35 ` tip-bot for Alexander Beregalov
0 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Alexander Beregalov @ 2010-01-13 10:35 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, a.beregalov, tglx, mingo
Commit-ID: 8d9e503928638fc95317be42c416fb7907322aff
Gitweb: http://git.kernel.org/tip/8d9e503928638fc95317be42c416fb7907322aff
Author: Alexander Beregalov <a.beregalov@gmail.com>
AuthorDate: Thu, 7 Jan 2010 19:40:47 +0300
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 13 Jan 2010 10:09:15 +0100
perf: Fix memory leak: counterwidth
Signed-off-by: Alexander Beregalov <a.beregalov@gmail.com>
Cc: a.p.zijlstra@chello.nl
Cc: paulus@samba.org
LKML-Reference: <1262882447-23776-2-git-send-email-a.beregalov@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
tools/perf/util/values.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/perf/util/values.c b/tools/perf/util/values.c
index 1c15e39..cfa55d6 100644
--- a/tools/perf/util/values.c
+++ b/tools/perf/util/values.c
@@ -169,6 +169,7 @@ static void perf_read_values__display_pretty(FILE *fp,
counterwidth[j], values->value[i][j]);
fprintf(fp, "\n");
}
+ free(counterwidth);
}
static void perf_read_values__display_raw(FILE *fp,
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-01-13 10:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-07 16:40 [PATCH 1/2] perf: add close()/closedir() calls when needed Alexander Beregalov
2010-01-07 16:40 ` [PATCH 2/2] perf: fix memory leak: counterwidth Alexander Beregalov
2010-01-13 10:35 ` [tip:perf/core] perf: Fix " tip-bot for Alexander Beregalov
2010-01-07 21:29 ` [PATCH 1/2] perf: add close()/closedir() calls when needed Paul Mackerras
2010-01-07 22:44 ` Alexander Beregalov
2010-01-07 23:54 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).