Coverage Report

Created: 2026-03-13 19:44

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
#if defined(__has_feature)
25
#if __has_feature(address_sanitizer)
26
#if defined(__linux__)
27
28
#undef ANNOTATE_LEAKING_OBJECT_PTR
29
#define ANNOTATE_LEAKING_OBJECT_PTR(p) __lsan_ignore_object(p);
30
31
#endif
32
#endif
33
#endif
34
35
// API definitions from LLVM lsan_interface.h
36
37
extern "C" {
38
// Allocations made between calls to __lsan_disable() and __lsan_enable() will
39
// be treated as non-leaks. Disable/enable pairs may be nested.
40
void __lsan_disable();
41
void __lsan_enable();
42
43
// The heap object into which p points will be treated as a non-leak.
44
void __lsan_ignore_object(const void* p);
45
46
// The user may optionally provide this function to disallow leak checking
47
// for the program it is linked into (if the return value is non-zero). This
48
// function must be defined as returning a constant value; any behavior beyond
49
// that is unsupported.
50
int __lsan_is_turned_off();
51
52
// Check for leaks now. This function behaves identically to the default
53
// end-of-process leak check. In particular, it will terminate the process if
54
// leaks are found and the exitcode runtime flag is non-zero.
55
// Subsequent calls to this function will have no effect and end-of-process
56
// leak check will not run. Effectively, end-of-process leak check is moved to
57
// the time of first invocation of this function.
58
// By calling this function early during process shutdown, you can instruct
59
// LSan to ignore shutdown-only leaks which happen later on.
60
void __lsan_do_leak_check();
61
62
// Check for leaks now. Returns zero if no leaks have been found or if leak
63
// detection is disabled, non-zero otherwise.
64
// This function may be called repeatedly, e.g. to periodically check a
65
// long-running process. It prints a leak report if appropriate, but does not
66
// terminate the process. It does not affect the behavior of
67
// __lsan_do_leak_check() or the end-of-process leak check, and is not
68
// affected by them.
69
int __lsan_do_recoverable_leak_check();
70
} // extern "C"
71
72
namespace doris::debug {
73
74
class ScopedLSANDisabler {
75
public:
76
14
    ScopedLSANDisabler() { __lsan_disable(); }
77
14
    ~ScopedLSANDisabler() { __lsan_enable(); }
78
};
79
80
} // namespace doris::debug