Skip to content

in g++, asan fails to detect a memory leak #1774

@mmomtchev

Description

@mmomtchev

I am not very sure if this belongs here or with g++, but here it is:

#include <iostream>
#include <vector>

class Object {
public:
  Object() = default;

private:
  int data;
};

int main() {
  auto *list = new std::vector<Object>;
  std::cout << list << std::endl;
  return 0;
}

Compile with

g++ -g -O0 -o test_asan -fsanitize=address,leak test_asan.cc

No leak detected

Compile with

clang++ -g -O0 -o test_asan -fsanitize=address,leak test_asan.cc

Leak detected

Tried with both g++ 11.4 and 13.2 (Ubuntu 22.04 and Ubuntu 24.04).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions