Skip to content

Commit 21d40c8

Browse files
committed
Issue # 1072: add LSAN_DO_LEAK_CHECK macro
1 parent 32286a2 commit 21d40c8

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/dispatch.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "log_private.h"
3131
#include "message_private.h"
3232
#include "policy.h"
33+
#include "qd_asan_interface.h"
3334
#include "router_private.h"
3435

3536
#include "qpid/dispatch/alloc.h"
@@ -373,6 +374,9 @@ void qd_dispatch_free(qd_dispatch_t *qd)
373374
{
374375
if (!qd) return;
375376

377+
// TODO: strawman proposal, do lsan leakcheck right here
378+
LSAN_DO_LEAK_CHECK();
379+
376380
/* Stop HTTP threads immediately */
377381
qd_http_server_free(qd_server_http(qd->server));
378382

src/qd_asan_interface.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ extern "C" {
5454

5555
void __asan_poison_memory_region(void const volatile *addr, size_t size);
5656
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
57+
void __lsan_do_leak_check(void);
58+
int __lsan_do_recoverable_leak_check(void);
5759

5860
/// Marks a memory region as unaddressable.
5961
///
@@ -73,6 +75,25 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
7375
/// \param size Size of memory region.
7476
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) __asan_unpoison_memory_region((addr), (size))
7577

78+
// Check for leaks now. This function behaves identically to the default
79+
// end-of-process leak check. In particular, it will terminate the process if
80+
// leaks are found and the exitcode runtime flag is non-zero.
81+
// Subsequent calls to this function will have no effect and end-of-process
82+
// leak check will not run. Effectively, end-of-process leak check is moved to
83+
// the time of first invocation of this function.
84+
// By calling this function early during process shutdown, you can instruct
85+
// LSan to ignore shutdown-only leaks which happen later on.
86+
#define LSAN_DO_LEAK_CHECK() __lsan_do_leak_check()
87+
88+
// Check for leaks now. Returns zero if no leaks have been found or if leak
89+
// detection is disabled, non-zero otherwise.
90+
// This function may be called repeatedly, e.g. to periodically check a
91+
// long-running process. It prints a leak report if appropriate, but does not
92+
// terminate the process. It does not affect the behavior of
93+
// __lsan_do_leak_check() or the end-of-process leak check, and is not
94+
// affected by them.
95+
#define LSAN_DO_RECOVERABLE_LEAK_CHECK() __lsan_do_recoverable_leak_check()
96+
7697
#ifdef __cplusplus
7798
} // extern "C"
7899
#endif
@@ -84,6 +105,9 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
84105
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
85106
((void)(addr), (void)(size))
86107

108+
#define LSAN_DO_LEAK_CHECK() /**/
109+
#define LSAN_DO_RECOVERABLE_LEAK_CHECK() 0
110+
87111
#endif // QD_HAS_ADDRESS_SANITIZER
88112

89113
// https://github.com/google/sanitizers/wiki/AddressSanitizer#turning-off-instrumentation

0 commit comments

Comments
 (0)