Skip to content

Commit ddf63da

Browse files
committed
get rid of memory leak
1 parent 75e236c commit ddf63da

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

cloud/filestore/libs/storage/tablet/bench/tablet_bench.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
#include <library/cpp/testing/benchmark/bench.h>
77

8+
#include <util/generic/singleton.h>
89
#include <util/generic/vector.h>
910

10-
#include <atomic>
1111
#include <memory>
1212

1313
using namespace NCloud;
@@ -70,27 +70,10 @@ struct TTabletSetup
7070
}
7171
};
7272

73-
// Using a non-owning static variable because the test Actor System crashes
74-
// during initialization.
75-
// A singleton also doesn’t work because it causes
76-
// other issues during deinitialization.
77-
// A memory leak is the price we pay to prevent the program from crashing.
78-
// This is acceptable because benchmarks are not run under sanitizers
79-
std::atomic<TTabletSetup*> Tablet = nullptr;
80-
8173
TTabletSetup* GetOrCreateTablet()
8274
{
83-
if (Tablet.load()) {
84-
return Tablet.load();
85-
}
86-
87-
auto tmp = std::make_unique<TTabletSetup>();
88-
TTabletSetup* expected = nullptr;
89-
if (!Tablet.compare_exchange_strong(expected, tmp.get())) {
90-
return Tablet.load();
91-
}
92-
93-
return tmp.release();
75+
constexpr ui64 Priority = Max<ui64>();
76+
return SingletonWithPriority<TTabletSetup, Priority>();
9477
}
9578

9679
} // namespace

cloud/filestore/libs/storage/tablet/bench/ya.make

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Y_BENCHMARK()
22

3-
NO_SANITIZE()
3+
IF (SANITIZER_TYPE)
4+
TAG(ya:manual)
5+
ENDIF()
6+
47

58
SRCS(
69
tablet_bench.cpp

contrib/ydb/library/actors/util/local_process_key.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ class TEnumProcessKey {
131131

132132
static size_t GetIndex(const EnumT key) {
133133
ui32 index = static_cast<ui32>(key);
134-
Y_ABORT_UNLESS(index < Enum2Index.size());
135-
return Enum2Index[index];
134+
const auto& enum2Index = Singleton<TEnum2Index>()->Enum2Index;
135+
Y_ABORT_UNLESS(index < enum2Index.size());
136+
return enum2Index[index];
136137
}
137138

138139
private:
@@ -153,5 +154,8 @@ class TEnumProcessKey {
153154
return enum2Index;
154155
}
155156

156-
inline static TVector<size_t> Enum2Index = RegisterAll();
157+
struct TEnum2Index
158+
{
159+
TVector<size_t> Enum2Index = RegisterAll();
160+
};
157161
};

0 commit comments

Comments
 (0)