http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51459
Bug #: 51459 Summary: [4.6 Regression] 'double free or corruption' involving std::function, std::vector and lambdas Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: kenn...@gmail.com Tested with "gcc version 4.7.0 20111112" on 64-bit Linux. ~~~~~~~~~~~~~~~~~ #include <vector> #include <functional> template <typename F> std::function<void()> animate(F f) { return [=]{ f(); }; } int main() { std::vector<double> pv {0, 0}; pv.push_back(0); std::function<void()> linear1 = []{}; std::vector<std::function<void()>> av {animate(linear1), animate(linear1)}; av[0](); return 0; } ~~~~~~~~~~~~~~~~~ Compiling and running this (`g++-4.7 -std=c++11 x.cpp`) results in: *** glibc detected *** ./a.out: double free or corruption (fasttop): 0x0000000001c7b1c0 *** ======= Backtrace: ========= /lib/libc.so.6(+0x73466)[0x7fafc7a78466] /lib/libc.so.6(cfree+0x6c)[0x7fafc7a7c33c] .... ~~~~~~~~~~~~~~~~~ g++-4.7 -v: Using built-in specs. COLLECT_GCC=g++-4.7 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: /tmp/packerbuild-0/gcc-snapshot/gcc-snapshot/src/gcc-4.7-20111112/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share/gcc-4.7 --with-bugurl='http://aur.archlinux.org/packages.php?ID=16045' --enable-languages=c,c++,lto --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-multilib --disable-libssp --disable-libstdcxx-pch --enable-checking=release --disable-werror --program-suffix=-4.7 --enable-version-specific-runtime-libs --disable-bootstrap Thread model: posix gcc version 4.7.0 20111112 (experimental) (GCC)