瀏覽代碼

common/wall_clock: Add virtual destructors

From -fsanitize=address, this code wasn't calling the proper destructor.
Adding virtual destructors for each inherited class and the base class
fixes this bug.

While we are at it, mark the functions as final.
ReinUsesLisp 5 年之前
父節點
當前提交
771a9c21cc
共有 3 個文件被更改,包括 4 次插入2 次删除
  1. 1 1
      src/common/wall_clock.cpp
  2. 2 0
      src/common/wall_clock.h
  3. 1 1
      src/common/x64/native_clock.h

+ 1 - 1
src/common/wall_clock.cpp

@@ -15,7 +15,7 @@ namespace Common {
 using base_timer = std::chrono::steady_clock;
 using base_time_point = std::chrono::time_point<base_timer>;
 
-class StandardWallClock : public WallClock {
+class StandardWallClock final : public WallClock {
 public:
     StandardWallClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency)
         : WallClock(emulated_cpu_frequency, emulated_clock_frequency, false) {

+ 2 - 0
src/common/wall_clock.h

@@ -13,6 +13,8 @@ namespace Common {
 
 class WallClock {
 public:
+    virtual ~WallClock() = default;
+
     /// Returns current wall time in nanoseconds
     [[nodiscard]] virtual std::chrono::nanoseconds GetTimeNS() = 0;
 

+ 1 - 1
src/common/x64/native_clock.h

@@ -12,7 +12,7 @@
 namespace Common {
 
 namespace X64 {
-class NativeClock : public WallClock {
+class NativeClock final : public WallClock {
 public:
     NativeClock(u64 emulated_cpu_frequency, u64 emulated_clock_frequency, u64 rtsc_frequency);