Skip to content

Commit

Permalink
Fix memory leak in TlsRandomNumberGenerator() constructor open-teleme…
Browse files Browse the repository at this point in the history
  • Loading branch information
hongweipeng committed May 7, 2024
1 parent da8e377 commit e6b5f8b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sdk/src/common/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
Expand All @@ -20,13 +21,16 @@ 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 e6b5f8b

Please sign in to comment.