Skip to content

AddressSanitizer error when using libc++ from apt.llvm.orgΒ #52771

@yachoor

Description

@yachoor

Recently (since around 10th November) my AddressSanitizer builds started failing with alloc-dealloc-mismatch in libc++ and libc++abi:

=================================================================
==1434378==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new vs free) on 0x604000000090
    #0 0x49eeb2 in free (/home/jchorko/test/a.out+0x49eeb2) (BuildId: 91122a1096e4968986fc59eafa1f74bea3cd2fbf)
    #1 0x7f67be96705d in std::range_error::~range_error() (/lib/x86_64-linux-gnu/libc++abi.so.1+0x2505d) (BuildId: ec7530f4e7d3b344a16572b564800c87973d8d4e)
    #2 0x7f67be969453 in __cxa_end_catch (/lib/x86_64-linux-gnu/libc++abi.so.1+0x27453) (BuildId: ec7530f4e7d3b344a16572b564800c87973d8d4e)
    #3 0x4dc076 in main (/home/jchorko/test/a.out+0x4dc076) (BuildId: 91122a1096e4968986fc59eafa1f74bea3cd2fbf)
    #4 0x7f67be5df564 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28564) (BuildId: 2b48299781548c9bc452eac6df39902547c884ed)
    #5 0x41d38d in _start (/home/jchorko/test/a.out+0x41d38d) (BuildId: 91122a1096e4968986fc59eafa1f74bea3cd2fbf)

0x604000000090 is located 0 bytes inside of 34-byte region [0x604000000090,0x6040000000b2)
allocated by thread T0 here:
    #0 0x4d997d in operator new(unsigned long) (/home/jchorko/test/a.out+0x4d997d) (BuildId: 91122a1096e4968986fc59eafa1f74bea3cd2fbf)
    #1 0x7f67be9d593f in std::runtime_error::runtime_error(char const*) (/lib/x86_64-linux-gnu/libc++.so.1+0x4f93f) (BuildId: bf8e70f0936248992f696c1e5117e394b302423d)
    #2 0x7f67be5df564 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28564) (BuildId: 2b48299781548c9bc452eac6df39902547c884ed)

SUMMARY: AddressSanitizer: alloc-dealloc-mismatch (/home/jchorko/test/a.out+0x49eeb2) (BuildId: 91122a1096e4968986fc59eafa1f74bea3cd2fbf) in free
==1434378==HINT: if you don't care about these errors you may set ASAN_OPTIONS=alloc_dealloc_mismatch=0
==1434378==ABORTING

This is example code that triggers it:

#include <stdexcept>
#include <cstdio>

int main() {
  try {
    throw std::runtime_error("Bad value");
  } catch (const std::runtime_error& e) {
    printf("%s\n", e.what());
  }

  return 0;
}

Compiled and run with:
clang++ -fno-omit-frame-pointer -stdlib=libc++ -fsanitize=address test.cpp && ./a.out

Compiler (and corresponding libc++/libc++abi packages) version:

Ubuntu clang version 14.0.0-++20211214104537+47eec789ed9c-1~exp1~20211214104630.167
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++abilibc++abi C++ Runtime Library. Not libc++.packaging

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions