summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAndres Noetzli <andres.noetzli@gmail.com>2017-09-20 11:24:13 -0700
committerGitHub <noreply@github.com>2017-09-20 11:24:13 -0700
commit54ed57102bbd35241c68d128f88bf2b93dd236cf (patch)
tree3e98176560c7867e545aac203cae25c6f527b32a /src/main
parent480df3b40de9650387c5fceb9aee39311753e3ab (diff)
Fix issue #1081, memory leak in cmd executor (#1109)
The variable `g` could be set multiple times depending on the options (e.g. a combination of `--dump-unsat-cores` and `--dump-synth`), which could lead to memory leaks and missing output. This commit fixes the issue by replacing `g` with a list of `getterCommands` that are all executed and deleted.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/command_executor.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/main/command_executor.cpp b/src/main/command_executor.cpp
index a18bb1fe4..7c8ee7827 100644
--- a/src/main/command_executor.cpp
+++ b/src/main/command_executor.cpp
@@ -20,7 +20,9 @@
#include <cassert>
#include <iostream>
+#include <memory>
#include <string>
+#include <vector>
#include "main/main.h"
#include "smt/command.h"
@@ -130,15 +132,15 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
// dump the model/proof/unsat core if option is set
if (status) {
- Command* g = NULL;
+ std::vector<std::unique_ptr<Command> > getterCommands;
if (d_options.getProduceModels() && d_options.getDumpModels() &&
(res.asSatisfiabilityResult() == Result::SAT ||
(res.isUnknown() && res.whyUnknown() == Result::INCOMPLETE))) {
- g = new GetModelCommand();
+ getterCommands.emplace_back(new GetModelCommand());
}
if (d_options.getProof() && d_options.getDumpProofs() &&
res.asSatisfiabilityResult() == Result::UNSAT) {
- g = new GetProofCommand();
+ getterCommands.emplace_back(new GetProofCommand());
}
if (d_options.getDumpInstantiations() &&
@@ -146,26 +148,30 @@ bool CommandExecutor::doCommandSingleton(Command* cmd)
(res.asSatisfiabilityResult() == Result::SAT ||
(res.isUnknown() && res.whyUnknown() == Result::INCOMPLETE))) ||
res.asSatisfiabilityResult() == Result::UNSAT)) {
- g = new GetInstantiationsCommand();
+ getterCommands.emplace_back(new GetInstantiationsCommand());
}
if (d_options.getDumpSynth() &&
res.asSatisfiabilityResult() == Result::UNSAT) {
- g = new GetSynthSolutionCommand();
+ getterCommands.emplace_back(new GetSynthSolutionCommand());
}
if (d_options.getDumpUnsatCores() &&
res.asSatisfiabilityResult() == Result::UNSAT) {
- g = new GetUnsatCoreCommand();
+ getterCommands.emplace_back(new GetUnsatCoreCommand());
}
- if (g != NULL) {
+ if (!getterCommands.empty()) {
// set no time limit during dumping if applicable
if (d_options.getForceNoLimitCpuWhileDump()) {
setNoLimitCPU();
}
- status = doCommandSingleton(g);
- delete g;
+ for (const auto& getterCommand : getterCommands) {
+ status = doCommandSingleton(getterCommand.get());
+ if (!status && !d_options.getContinuedExecution()) {
+ break;
+ }
+ }
}
}
return status;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback