Coverage Report

Created: 2026-06-16 22:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/debug/leak_annotations.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
// Ignore a single leaked object, given its pointer.
21
// Does nothing if LeakSanitizer is not enabled.
22
#define ANNOTATE_LEAKING_OBJECT_PTR(p)
23
24
// Check if LeakSanitizer is enabled
25
#if defined(__has_feature)
26
#if __has_feature(address_sanitizer) || __has_feature(leak_sanitizer)
27
#define DORIS_LSAN_ENABLED 1
28
#endif
29
#endif
30
31
#if !defined(DORIS_LSAN_ENABLED) && (defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER))
32
#define DORIS_LSAN_ENABLED 1
33
#endif
34
35
// DORIS_LSAN_ENABLED && __linux__
36
#if defined(DORIS_LSAN_ENABLED) && defined(__linux__)
37
38
#undef ANNOTATE_LEAKING_OBJECT_PTR
39
1
#define ANNOTATE_LEAKING_OBJECT_PTR(p) __lsan_ignore_object(p);
40
41
#endif // DORIS_LSAN_ENABLED && __linux__
42
43
// API definitions from LLVM lsan_interface.h
44
45
extern "C" {
46
// Allocations made between calls to __lsan_disable() and __lsan_enable() will
47
// be treated as non-leaks. Disable/enable pairs may be nested.
48
void __lsan_disable();
49
void __lsan_enable();
50
51
// The heap object into which p points will be treated as a non-leak.
52
void __lsan_ignore_object(const void* p);
53
54
// The user may optionally provide this function to disallow leak checking
55
// for the program it is linked into (if the return value is non-zero). This
56
// function must be defined as returning a constant value; any behavior beyond
57
// that is unsupported.
58
int __lsan_is_turned_off();
59
60
// Check for leaks now. This function behaves identically to the default
61
// end-of-process leak check. In particular, it will terminate the process if
62
// leaks are found and the exitcode runtime flag is non-zero.
63
// Subsequent calls to this function will have no effect and end-of-process
64
// leak check will not run. Effectively, end-of-process leak check is moved to
65
// the time of first invocation of this function.
66
// By calling this function early during process shutdown, you can instruct
67
// LSan to ignore shutdown-only leaks which happen later on.
68
void __lsan_do_leak_check();
69
70
// Check for leaks now. Returns zero if no leaks have been found or if leak
71
// detection is disabled, non-zero otherwise.
72
// This function may be called repeatedly, e.g. to periodically check a
73
// long-running process. It prints a leak report if appropriate, but does not
74
// terminate the process. It does not affect the behavior of
75
// __lsan_do_leak_check() or the end-of-process leak check, and is not
76
// affected by them.
77
int __lsan_do_recoverable_leak_check();
78
} // extern "C"
79
80
namespace doris::debug {
81
82
class ScopedLSANDisabler {
83
public:
84
14
    ScopedLSANDisabler() { __lsan_disable(); }
85
14
    ~ScopedLSANDisabler() { __lsan_enable(); }
86
};
87
88
} // namespace doris::debug