aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClifford Wolf <clifford@clifford.at>2019-05-15 13:51:02 +0200
committerClifford Wolf <clifford@clifford.at>2019-05-15 13:51:02 +0200
commitf67ec1b2350c3bd88edacba7ad799bf60b33da61 (patch)
tree7530c23e32a80ae30699488bc5cfef3ace109c61
parent4fd0e11214293ebdd7751bd2181b0e7399a80ed6 (diff)
downloadyosys-f67ec1b2350c3bd88edacba7ad799bf60b33da61.tar.gz
yosys-f67ec1b2350c3bd88edacba7ad799bf60b33da61.tar.bz2
yosys-f67ec1b2350c3bd88edacba7ad799bf60b33da61.zip
Do not leak file descriptors in cover.cc
Signed-off-by: Clifford Wolf <clifford@clifford.at>
-rw-r--r--passes/cmds/cover.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/passes/cmds/cover.cc b/passes/cmds/cover.cc
index 721ebded4..1128116b4 100644
--- a/passes/cmds/cover.cc
+++ b/passes/cmds/cover.cc
@@ -98,22 +98,23 @@ struct CoverPass : public Pass {
}
if ((args[argidx] == "-o" || args[argidx] == "-a" || args[argidx] == "-d") && argidx+1 < args.size()) {
const char *open_mode = args[argidx] == "-a" ? "a+" : "w";
- std::string filename = args[++argidx];
+ const std::string &filename = args[++argidx];
+ FILE *f = nullptr;
if (args[argidx-1] == "-d") {
#ifdef _WIN32
log_cmd_error("The 'cover -d' option is not supported on win32.\n");
#else
char filename_buffer[4096];
snprintf(filename_buffer, 4096, "%s/yosys_cover_%d_XXXXXX.txt", filename.c_str(), getpid());
- mkstemps(filename_buffer, 4);
- filename = filename_buffer;
+ f = fdopen(mkstemps(filename_buffer, 4), "w");
#endif
+ } else {
+ f = fopen(filename.c_str(), open_mode);
}
- FILE *f = fopen(filename.c_str(), open_mode);
if (f == NULL) {
for (auto f : out_files)
fclose(f);
- log_cmd_error("Can't create file %s.\n", args[argidx].c_str());
+ log_cmd_error("Can't create file %s%s.\n", args[argidx-1] == "-d" ? "in directory " : "", args[argidx].c_str());
}
out_files.push_back(f);
continue;