Skip to content

Commit 8b37a4e

Browse files
committed
[sanitizer] Make destructors protected
1 parent b0f1d7d commit 8b37a4e

10 files changed

+14
-9
lines changed

compiler-rt/lib/asan/asan_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AsanThread;
3535

3636
// These objects are created for every thread and are never deleted,
3737
// so we can find them by tid even if the thread is long dead.
38-
class AsanThreadContext : public ThreadContextBase {
38+
class AsanThreadContext final : public ThreadContextBase {
3939
public:
4040
explicit AsanThreadContext(int tid)
4141
: ThreadContextBase(tid), announced(false),

compiler-rt/lib/lsan/lsan_posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct DTLS;
2727

2828
namespace __lsan {
2929

30-
class ThreadContext : public ThreadContextLsanBase {
30+
class ThreadContext final : public ThreadContextLsanBase {
3131
public:
3232
explicit ThreadContext(int tid);
3333
void OnStarted(void *arg) override;

compiler-rt/lib/lsan/lsan_thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ThreadContextLsanBase : public ThreadContextBase {
3232
void *onstarted_arg);
3333

3434
protected:
35+
~ThreadContextLsanBase(){};
3536
uptr stack_begin_ = 0;
3637
uptr stack_end_ = 0;
3738
uptr cache_begin_ = 0;

compiler-rt/lib/memprof/memprof_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MemprofThread;
3434

3535
// These objects are created for every thread and are never deleted,
3636
// so we can find them by tid even if the thread is long dead.
37-
struct MemprofThreadContext : public ThreadContextBase {
37+
struct MemprofThreadContext final : public ThreadContextBase {
3838
explicit MemprofThreadContext(int tid)
3939
: ThreadContextBase(tid), announced(false),
4040
destructor_iterations(GetPthreadDestructorIterations()), stack_id(0),

compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct DDLogicalThread {
3232
bool report_pending;
3333
};
3434

35-
struct DD : public DDetector {
35+
struct DD final : public DDetector {
3636
SpinMutex mtx;
3737
DeadlockDetector<DDBV> dd;
3838
DDFlags flags;

compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct Mutex {
8080
Link link[kMaxLink];
8181
};
8282

83-
struct DD : public DDetector {
83+
struct DD final : public DDetector {
8484
explicit DD(const DDFlags *flags);
8585

8686
DDPhysicalThread* CreatePhysicalThread();

compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ struct DDetector {
8585
virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {}
8686

8787
virtual DDReport *GetReport(DDCallback *cb) { return nullptr; }
88+
89+
protected:
90+
~DDetector(){};
8891
};
8992

9093
} // namespace __sanitizer

compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ enum class ThreadType {
3939
class ThreadContextBase {
4040
public:
4141
explicit ThreadContextBase(u32 tid);
42-
~ThreadContextBase(); // Should never be called.
43-
4442
const u32 tid; // Thread ID. Main thread should have tid = 0.
4543
u64 unique_id; // Unique thread ID.
4644
u32 reuse_count; // Number of times this tid was reused.
@@ -80,6 +78,9 @@ class ThreadContextBase {
8078
virtual void OnCreated(void *arg) {}
8179
virtual void OnReset() {}
8280
virtual void OnDetached(void *arg) {}
81+
82+
protected:
83+
~ThreadContextBase();
8384
};
8485

8586
typedef ThreadContextBase* (*ThreadContextFactory)(u32 tid);

compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct RunThreadArgs {
162162
uptr shard; // started from 1.
163163
};
164164

165-
class TestThreadContext : public ThreadContextBase {
165+
class TestThreadContext final : public ThreadContextBase {
166166
public:
167167
explicit TestThreadContext(int tid) : ThreadContextBase(tid) {}
168168
void OnJoined(void *arg) {

compiler-rt/lib/tsan/rtl/tsan_rtl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ inline void cur_thread_finalize() { }
477477
#endif // SANITIZER_MAC || SANITIZER_ANDROID
478478
#endif // SANITIZER_GO
479479

480-
class ThreadContext : public ThreadContextBase {
480+
class ThreadContext final : public ThreadContextBase {
481481
public:
482482
explicit ThreadContext(int tid);
483483
~ThreadContext();

0 commit comments

Comments
 (0)