1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-01 14:41:00 +01:00

Make 'logger' a std::unique_ptr

This prevents it from being leaked (see
bb411e4ae1 for an example of this).
This commit is contained in:
Eelco Dolstra 2022-08-25 16:57:03 +02:00
parent 1f688d62d7
commit 2018413e3e
8 changed files with 45 additions and 42 deletions

View file

@ -117,13 +117,15 @@ public:
{
{
auto state(state_.lock());
if (!state->active) return;
state->active = false;
writeToStderr("\r\e[K");
updateCV.notify_one();
quitCV.notify_one();
if (state->active) {
state->active = false;
writeToStderr("\r\e[K");
updateCV.notify_one();
quitCV.notify_one();
}
}
updateThread.join();
if (updateThread.joinable())
updateThread.join();
}
void pause() override {
@ -553,9 +555,9 @@ public:
}
};
Logger * makeProgressBar()
std::unique_ptr<Logger> makeProgressBar()
{
return new ProgressBar(isTTY());
return std::make_unique<ProgressBar>(isTTY());
}
void startProgressBar()
@ -565,9 +567,8 @@ void startProgressBar()
void stopProgressBar()
{
auto progressBar = dynamic_cast<ProgressBar *>(logger);
if (progressBar) progressBar->stop();
if (auto progressBar = dynamic_cast<ProgressBar *>(logger.get()))
progressBar->stop();
}
}