diff options
author | Alexander Sverdlin <alexander.sverdlin@gmail.com> | 2015-03-29 20:44:04 +0200 |
---|---|---|
committer | Daniel Mack <daniel@zonque.org> | 2015-03-30 09:37:11 +0200 |
commit | 58ec01b35c046f5f167763343514c20170bfd2eb (patch) | |
tree | f5e06ce17cad77795f29ce7728c106871623fead /src/bootchart/svg.c | |
parent | 9964a9eb7b18d6ad172a7921cf88efabde05d121 (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/svg.c')
-rw-r--r-- | src/bootchart/svg.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/bootchart/svg.c b/src/bootchart/svg.c index e1fc531ba9..54129159ac 100644 --- a/src/bootchart/svg.c +++ b/src/bootchart/svg.c @@ -170,6 +170,9 @@ static void svg_title(const char *build) { if (!fgets(cmdline, 255, f)) sprintf(cmdline, "Unknown"); fclose(f); + } else { + if (fd >= 0) + close(fd); } /* extract root fs so we can find disk model name in sysfs */ @@ -185,6 +188,9 @@ static void svg_title(const char *build) { if (!fgets(model, 255, f)) fprintf(stderr, "Error reading disk model for %s\n", rootbdev); fclose(f); + } else { + if (fd >= 0) + close(fd); } } @@ -208,6 +214,9 @@ static void svg_title(const char *build) { } } fclose(f); + } else { + if (fd >= 0) + close(fd); } svg("<text class=\"t1\" x=\"0\" y=\"30\">Bootchart for %s - %s</text>\n", |