1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 19:57:59 +02: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

@ -29,7 +29,7 @@ void setCurActivity(const ActivityId activityId)
curActivity = activityId;
}
Logger * logger = makeSimpleLogger(true);
std::unique_ptr<Logger> logger = makeSimpleLogger(true);
void Logger::warn(const std::string & msg)
{
@ -128,9 +128,9 @@ void writeToStderr(std::string_view s)
}
}
Logger * makeSimpleLogger(bool printBuildLogs)
std::unique_ptr<Logger> makeSimpleLogger(bool printBuildLogs)
{
return new SimpleLogger(printBuildLogs);
return std::make_unique<SimpleLogger>(printBuildLogs);
}
std::atomic<uint64_t> nextId{0};
@ -262,9 +262,9 @@ struct JSONLogger : Logger {
}
};
Logger * makeJSONLogger(Descriptor fd)
std::unique_ptr<Logger> makeJSONLogger(Descriptor fd)
{
return new JSONLogger(fd);
return std::make_unique<JSONLogger>(fd);
}
static Logger::Fields getFields(nlohmann::json & json)