Skip to content

Commit

Permalink
Merge pull request #16 from ethz-asl/fix/memory_leaks
Browse files Browse the repository at this point in the history
Fixed LogPolicy memory leak
  • Loading branch information
4c3y authored Jul 21, 2023
2 parents c1e39c0 + a88b52c commit dfbacd1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions include/log++.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <chrono>
#include <mutex>
#include <functional>
#include <memory>

#if !defined MODE_LPP && !defined MODE_GLOG && !defined MODE_ROSLOG && !defined MODE_DEFAULT
#define MODE_DEFAULT
Expand Down Expand Up @@ -619,22 +620,24 @@ enum PolicyType {
TIMED
};

typedef std::shared_ptr<LogPolicy> LogPolicyPtr;

class LogPolicyFactory {
public:
static LogPolicy *create(PolicyType policy_type, int max) {
static LogPolicyPtr create(PolicyType policy_type, int max) {
switch (policy_type) {
case FIRST_N: return new FirstNOccurrencesPolicy(max);
case EVERY_N: return new OccasionPolicy(max);
case TIMED: return new TimePolicy(max);
default:abort();
case FIRST_N: return std::make_shared<FirstNOccurrencesPolicy>(max);
case EVERY_N: return std::make_shared<OccasionPolicy>(max);
case TIMED: return std::make_shared<TimePolicy>(max);
default:abort();
}
}
};

struct LogStatementData {
LogStatementData(LogPolicy *log_policy, BaseSeverity severity_type)
: log_policy_(log_policy), severity_type_(severity_type) {}
LogPolicy *log_policy_;
LogStatementData(LogPolicyPtr log_policy, BaseSeverity severity_type)
: log_policy_(std::move(log_policy)), severity_type_(severity_type) {}
LogPolicyPtr log_policy_;
std::string msg{};
BaseSeverity severity_type_;
};
Expand Down

0 comments on commit dfbacd1

Please sign in to comment.