Skip to content

[ASAN] AddressSanitizer FN, failed to report memory leaks #110360

Open
@wr-web

Description

@wr-web

reproduce: https://godbolt.org/z/WEjY9rY1G
bug code:

#include <iostream>

void unsuspectingBug() {
    int* ptr = new int(42);

    // Perform some logical operations that don't affect ptr directly
    for (int i = 0; i < 100; ++i) {
        int temp = i * i; // Irrelevant computation
        if (temp == 42) {
            delete ptr;
        }
    }

    // Forgetting to nullify ptr after deletion
    // Logical usage without realizing it's been erased
    if (ptr) {
        std::cout << *ptr << std::endl; // Dereference of dangling pointer not realized due to logical oversight
    }
}

int main() {
    unsuspectingBug();
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions