[英]Address sanitizer doesn't find missing delete statement
我在 Visual Studio 中为我的项目启用了 Address Sanitizer,并在Microsoft Learn的以下代码上成功测试了它。
#include <stdio.h>
int x[100];
int main() {
printf("Hello!\n");
x[100] = 5; // Boom!
return 0;
}
但是,消毒程序无法在以下代码中找到丢失的 delete 语句:
struct Object {
int x;
int y;
};
int main() {
Object* obj = new Object();
// Boom!
return 0;
}
查看生成的程序集,我们可以看到确实调用了新运算符并且没有优化掉。 以下 output 取自 Debug/x86 配置,但对于配置 Debug/x64、Release/x86 和 Release/x64 可以获得类似的输出。
; 6 : int main() {
push ebp
mov ebp, esp
sub esp, 12 ; 0000000cH
mov ecx, OFFSET __62A33F1D_Source@cpp
call @__CheckForDebuggerJustMyCode@4
; 7 : Object* obj = new Object();
push 8
call ??2@YAPAXI@Z ; operator new
Address Sanitizer 能否检测到此类错误? 如果是,我怎样才能成功检测到错误?
Microsoft address sanitizer 未检测到 memory 泄漏。 请参阅链接页面上的第二条注释。
... 向我们发送有关您希望在未来版本中看到的内容的反馈。 您的反馈有助于我们确定未来其他消毒剂的优先级,例如
/fsanitize=thread
、/fsanitize=leak
、/fsanitize=memory
……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.