aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/use_after_free_checker.h
blob: 590b0761568240027117b115e31b9c9f3152896a (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();
    }
};