lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1262882447-23776-1-git-send-email-a.beregalov@gmail.com>
Date:	Thu,  7 Jan 2010 19:40:46 +0300
From:	Alexander Beregalov <a.beregalov@...il.com>
To:	a.p.zijlstra@...llo.nl, paulus@...ba.org, mingo@...e.hu
Cc:	linux-kernel@...r.kernel.org,
	Alexander Beregalov <a.beregalov@...il.com>
Subject: [PATCH 1/2] perf: add close()/closedir() calls when needed

Close file and directory descriptors before exiting or dying.

Signed-off-by: Alexander Beregalov <a.beregalov@...il.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

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ