Skip to content

Commit

Permalink
Fix memory leak in TlsRandomNumberGenerator() constructor #2660
Browse files Browse the repository at this point in the history
  • Loading branch information
hongweipeng committed May 7, 2024
1 parent da8e377 commit c2ce0fb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sdk/src/common/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "src/common/platform/fork.h"

#include <cstring>
#include <mutex>
#include <random>

OPENTELEMETRY_BEGIN_NAMESPACE
Expand All @@ -20,13 +21,14 @@ namespace common
// https://github.com/opentracing-contrib/nginx-opentracing/issues/52
namespace
{
static std::once_flag once;
class TlsRandomNumberGenerator
{
public:
TlsRandomNumberGenerator() noexcept
{
Seed();
platform::AtFork(nullptr, nullptr, OnFork);
std::call_once(once, [](){ platform::AtFork(nullptr, nullptr, OnFork); });
}

static FastRandomNumberGenerator &engine() noexcept { return engine_; }
Expand Down

0 comments on commit c2ce0fb

Please sign in to comment.