简体   繁体   English

地址清理器找不到丢失的删除语句

[英]Address sanitizer doesn't find missing delete statement

I have enabled Address Sanitizer for my project in Visual Studio and successfully tested it on the following code from Microsoft Learn .我在 Visual Studio 中为我的项目启用了 Address Sanitizer,并在Microsoft Learn的以下代码上成功测试了它。

#include <stdio.h>

int x[100];

int main() {
    printf("Hello!\n");
    x[100] = 5; // Boom!
    return 0;
}

However, the sanitizer can't find the missing delete statement in the following code:但是,消毒程序无法在以下代码中找到丢失的 delete 语句:

struct Object {
    int x;
    int y;
};

int main() {
    Object* obj = new Object();
    // Boom!
    return 0;
}

Looking at the resulting assembly we can see that the new operator is indeed called and isn't optimized away.查看生成的程序集,我们可以看到确实调用了新运算符并且没有优化掉。 The following output is taken from Debug/x86 configuration but similar outputs can be obtained for configurations Debug/x64, Release/x86 and Release/x64.以下 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

Can Address Sanitizer detect this type of error? Address Sanitizer 能否检测到此类错误? If yes, how can I achieve a successful error detection?如果是,我怎样才能成功检测到错误?

Microsoft address sanitizer does not detect memory leaks. Microsoft address sanitizer 未检测到 memory 泄漏。 See the second note on the linked page .请参阅链接页面上的第二条注释。

... Send us feedback on what you'd like to see in future releases. ... 向我们发送有关您希望在未来版本中看到的内容的反馈。 Your feedback helps us prioritize other sanitizers for the future, such as /fsanitize=thread , /fsanitize=leak , /fsanitize=memory , ...您的反馈有助于我们确定未来其他消毒剂的优先级,例如/fsanitize=thread/fsanitize=leak/fsanitize=memory ……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM