aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/use_after_free_checker.h
blob: 7f6db63af7cd3f80cae23441f539a2af237a3028 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include <util/system/platform.h>
#include <util/system/types.h>

class TUseAfterFreeChecker {
private:
    ui64 Magic;
 
public:
    TUseAfterFreeChecker();
    ~TUseAfterFreeChecker();
    void CheckNotFreed() const;
};

// check twice: in constructor and in destructor
class TUseAfterFreeCheckerGuard {
private:
    const TUseAfterFreeChecker& Check;
 
public:
    TUseAfterFreeCheckerGuard(const TUseAfterFreeChecker& check)
        : Check(check)
    {
        Check.CheckNotFreed();
    }

    ~TUseAfterFreeCheckerGuard() {
        Check.CheckNotFreed();
    }
};