简体   繁体   中英

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 .

#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:

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.

; 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? If yes, how can I achieve a successful error detection?

Microsoft address sanitizer does not detect memory leaks. 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 , ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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