mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Fix potential race condidion when in logger copy ctor
Don't copy other.trace - just create a new one with same size instead
This commit is contained in:
parent
6ff52332a8
commit
3ea7fb18d6
@ -17,15 +17,20 @@ namespace details {
|
||||
class backtracer
|
||||
{
|
||||
std::mutex mutex_;
|
||||
size_t n_messages_;
|
||||
circular_q<log_msg_buffer> messages_;
|
||||
|
||||
public:
|
||||
explicit backtracer(size_t n_messages) : messages_{n_messages}
|
||||
explicit backtracer(size_t n_messages) : n_messages_{n_messages}, messages_{n_messages}
|
||||
{}
|
||||
|
||||
backtracer(const backtracer &other) : messages_{other.messages_}
|
||||
{}
|
||||
|
||||
|
||||
size_t n_messages() const
|
||||
{
|
||||
return n_messages_;
|
||||
}
|
||||
|
||||
|
||||
void add(const log_msg &msg)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock{mutex_};
|
||||
|
@ -25,7 +25,7 @@ SPDLOG_INLINE logger::logger(const logger &other)
|
||||
{
|
||||
if (other.tracer_)
|
||||
{
|
||||
tracer_ = std::make_shared<details::backtracer>(*other.tracer_);
|
||||
tracer_ = std::make_shared<details::backtracer>(other.tracer_->n_messages());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user