summaryrefslogtreecommitdiff
path: root/src/bootchart/store.c
diff options
context:
space:
mode:
authorAlexander Sverdlin <alexander.sverdlin@gmail.com>2015-03-29 20:44:04 +0200
committerDaniel Mack <daniel@zonque.org>2015-03-30 09:37:11 +0200
commit58ec01b35c046f5f167763343514c20170bfd2eb (patch)
treef5e06ce17cad77795f29ce7728c106871623fead /src/bootchart/store.c
parent9964a9eb7b18d6ad172a7921cf88efabde05d121 (diff)
systemd-bootchart: Prevent leaking file descriptors in open-fdopen combination
Correctly handle the potential failure of fdopen() (because of OOM, for instance) after potentially successful open(). Prevent leaking open fd in such case.
Diffstat (limited to 'src/bootchart/store.c')
-rw-r--r--src/bootchart/store.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bootchart/store.c b/src/bootchart/store.c
index 3900936acf..8e9a62f91d 100644
--- a/src/bootchart/store.c
+++ b/src/bootchart/store.c
@@ -330,9 +330,13 @@ schedstat_next:
/* ppid */
sprintf(filename, "%d/stat", pid);
fd = openat(procfd, filename, O_RDONLY);
+ if (fd == -1)
+ continue;
st = fdopen(fd, "r");
- if (!st)
+ if (!st) {
+ close(fd);
continue;
+ }
if (!fscanf(st, "%*s %*s %*s %i", &p)) {
continue;
}
@@ -432,9 +436,13 @@ schedstat_next:
if (!ps->smaps) {
sprintf(filename, "%d/smaps", pid);
fd = openat(procfd, filename, O_RDONLY);
+ if (fd == -1)
+ continue;
ps->smaps = fdopen(fd, "r");
- if (!ps->smaps)
+ if (!ps->smaps) {
+ close(fd);
continue;
+ }
setvbuf(ps->smaps, smaps_buf, _IOFBF, sizeof(smaps_buf));
}
else {