c++ - 如何在长时间运行的服务器程序上使用 asan?
问题描述
我有一个长时间运行的服务器程序,我想使用 asan 来检测这个程序的内存泄漏。我的解决方案:
CXXFLAGS+="-fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address"
LDFLAGS+="-lasan"
# start the program
LD_PRELOAD=libasan.so.5 ASAN_OPTIONS=halt_on_error=false:alloc_dealloc_mismatch=0 ./bin/server > asan_report 2>&1 &
但它似乎只报告一次我希望它定期报告,怎么做?
解决方案
我希望它定期报告
您可以__lsan_do_recoverable_leak_check();
在调度循环中的适当时间调用。
// Check for leaks now. Returns zero if no leaks have been found or if leak
// detection is disabled, non-zero otherwise.
// This function may be called repeatedly, e.g. to periodically check a
// long-running process. It prints a leak report if appropriate, but does not
// terminate the process. It does not affect the behavior of
// __lsan_do_leak_check() or the end-of-process leak check, and is not
// affected by them.
这将重复打印相同的泄漏(没有“仅打印自上次调用以来的新泄漏”功能)。
PS由于你的程序已经链接了libasan
,所以没有任何理由LD_PRELOAD
,并且有很多缺点。
推荐阅读
- c++ - C++ 变量不在循环中更新
- javascript - 在 Leaflet 中,如何计算从单击的标记到最远标记的距离?
- svelte-3 - 错误的苗条形式
- android - 麦克风无法正常工作 android 10 - 需要 adb dumpsys 帮助
- php - 如何摆脱“未捕获的类型错误:feof():提供的资源不是有效的流资源”记录的错误?
- python - Python 递增到要搜索的字符串中的下一个位置
- python - 对于 Python,为什么 Selenium 不读取 Geckodriver 却读取 Chromedriver?
- javascript - 异步/等待循环 array.push 问题
- xml - 在使用spring的XML响应期间在bean名称之后获取HibernateProxy.RV3cG0FE
- node.js - 如何使用 react-calendar 创建属于团队的事件?