summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2025-01-29 16:20:25 +0100
committerBarnabás Pőcze <pobrn@protonmail.com>2025-02-27 11:30:23 +0100
commit0fc00eacdb699de78af640a2d2811fa7cb9c5c3d (patch)
tree0c4dab7297dc021b04383595ab9e807b94038062
parent9ac914c6341817c31c002932e943c932cbffe5db (diff)
libcamera: base: log: Avoid manual `LogCategory` deletion
Wrap the `LogCategory` pointers in `std::unique_ptr` to avoid the need for manual deletion in the destructor. Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
-rw-r--r--src/libcamera/base/log.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 6c03da00..6a040b59 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -322,7 +322,7 @@ private:
static bool destroyed_;
Mutex mutex_;
- std::vector<LogCategory *> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
+ std::vector<std::unique_ptr<LogCategory>> categories_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
std::list<std::pair<std::string, LogSeverity>> levels_;
std::shared_ptr<LogOutput> output_;
@@ -439,9 +439,6 @@ void logSetLevel(const char *category, const char *level)
Logger::~Logger()
{
destroyed_ = true;
-
- for (LogCategory *category : categories_)
- delete category;
}
/**
@@ -574,7 +571,7 @@ void Logger::logSetLevel(const char *category, const char *level)
MutexLocker locker(mutex_);
- for (LogCategory *c : categories_) {
+ for (const auto &c : categories_) {
if (c->name() == category) {
c->setSeverity(severity);
break;
@@ -718,12 +715,12 @@ LogCategory *Logger::findOrCreateCategory(std::string_view name)
{
MutexLocker locker(mutex_);
- for (LogCategory *category : categories_) {
+ for (const auto &category : categories_) {
if (category->name() == name)
- return category;
+ return category.get();
}
- LogCategory *category = categories_.emplace_back(new LogCategory(name));
+ LogCategory *category = categories_.emplace_back(std::unique_ptr<LogCategory>(new LogCategory(name))).get();
const char *categoryName = category->name().c_str();
for (const auto &[pattern, severity] : levels_) {