如何启用 LSAN 在运行时检测内存泄漏,而不是等到进程结束

How to enable LSAN detect memory leaks at runtime, and not wait until the end of the process

我有一个 ASAN 检测的 'deamon' 进程,它始终在我的系统中运行。我看到只有在进程退出时才会报告内存泄漏。无论如何,我可以要求 LSAN 转储泄漏报告而不必终止进程吗?有没有我可以发送给进程的信号,以便它检测并转储泄漏?

使用__lsan_do_leak_check:

  // Check for leaks now. This function behaves identically to the default
  // end-of-process leak check. In particular, it will terminate the process if
  // leaks are found and the exitcode runtime flag is non-zero.
  // Subsequent calls to this function will have no effect and end-of-process
  // leak check will not run. Effectively, end-of-process leak check is moved to
  // the time of first invocation of this function.
  // By calling this function early during process shutdown, you can instruct
  // LSan to ignore shutdown-only leaks which happen later on.