[Bug c++/48751] New: Incorrect delete[] in c++/4.4/parallel/par_loop.h line 127
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48751 Summary: Incorrect delete[] in c++/4.4/parallel/par_loop.h line 127 Product: gcc Version: 4.4.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: t.h.shorr...@gmail.com __gnu_parallel::accumulate gives a segfault when accumulating over 1000 elements (but not 999). This was originally asked as a question on StackOverflow - http://stackoverflow.com/questions/5769908/unexpected-segfault-with-gnu-parallelaccumulate: Sehe diagnosed the problem as a bug in c++/4.4/parallel/par_loop.h:87 " # pragma omp single { num_threads = omp_get_num_threads(); thread_results = static_cast( ::operator new(num_threads * sizeof(Result))); constructed = new bool[num_threads]; } But line 127 deletes it with delete[] thread_results; _Apparently, the construction of thread_results was optimized at one stage, but the deletion statement was never updated to reflect this. The optimization makes sense over just newing up the array (new Result[num_threads]) because it avoids constructing the elements._ Fixing that to delete thread_results; removes the bug. You will want to report this to the gnu devs. " SYSTEM Ubuntu 10-10 on AMD64 dual core. TO RECREATE: #include #include #include class NaturalParameters { public: NaturalParameters() : m_data(2) //defualt constructor { } std::vector::const_iterator begin() const { return m_data.begin(); } std::vector::const_iterator end() const { return m_data.begin(); } NaturalParameters& operator+=(const NaturalParameters& other) { //do something - well actually ... nothing for the purposes of this bug report. return *this; } private: std::vector m_data; }; inline NaturalParameters operator+(const NaturalParameters& a, const NaturalParameters& b) { NaturalParameters tmp = a; return tmp+=b; } int main (int ac, char **av) { //This one succeeds for(size_t i=0;i<1000;++i){ std::vector ChildrenNP(999); NaturalParameters init; NaturalParameters NP = __gnu_parallel::accumulate(ChildrenNP.begin(), ChildrenNP.end(), init ); } //This one fails with a segfault for(size_t i=0;i<1000;++i){ std::vector ChildrenNP(1000); NaturalParameters init; NaturalParameters NP = __gnu_parallel::accumulate(ChildrenNP.begin(), ChildrenNP.end(), init ); } } Preprocessed file attached COMMAND: g++ -v gnu_parallel_bug.cpp -g -fopenmp -Wall -D_GLIBCXX_PARALLEL -save-temps Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) COLLECT_GCC_OPTIONS='-v' '-g' '-fopenmp' '-Wall' '-D_GLIBCXX_PARALLEL' '-save-temps' '-shared-libgcc' '-mtune=generic' '-pthread' /usr/lib/gcc/x86_64-linux-gnu/4.4.5/cc1plus -E -quiet -v -D_GNU_SOURCE -D_REENTRANT -D_GLIBCXX_PARALLEL gnu_parallel_bug.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -Wall -fopenmp -g -fworking-directory -fpch-preprocess -fstack-protector -o gnu_parallel_bug.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/usr/include/x86_64-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.4 /usr/include/c++/4.4/x86_64-linux-gnu /usr/include/c++/4.4/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.4.5/include /usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-g' '-fopenmp' '-Wall' '-D_GLIBCXX_PARALLEL' '-save-temps' '-shared-libgcc' '-mtune=generic' '-pthread' /usr/lib/gcc/x86_64-linux-gnu/4.4.5/cc1plus -fpreprocessed gnu_parallel_bug.ii -quiet -dumpbase gnu_parallel_bug.cpp -mtune=generic -auxbase gnu_parallel_bug -g -Wall -version -fopenmp -fstack-protector -o gnu_parallel_bug.s GNU C++ (Ubuntu/Linaro 4.4.4-14ubuntu5) version 4.4.5 (x86_64-linux-gnu) compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3. GGC heuristics: --param ggc-min-expand=
[Bug c++/48751] Incorrect delete[] in c++/4.4/parallel/par_loop.h line 127
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48751 --- Comment #1 from Tom 2011-04-24 12:05:10 UTC --- Sehe - who found the bug in response to my question submitted the bug report too, its here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48750 This is a repetition of this report.
[Bug libstdc++/48750] for_each_template_random_access_ed has unbalanced new/delete[]
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48750 --- Comment #10 from Tom 2011-04-26 18:09:05 UTC --- Hi Paulo, Yes, this certainly fixes my segfault. Valgrind complains a little - although I am not sure if this is important (I am very new to the helgrind tool). In case it is useful, I attach the output I get, So the line numbers are meaningful, I include my modified par_loop.h and my test file. Here is my g++ -v Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5) running on Ubuntu 10-10 Many thanks for your assistance with this. My gratitude to the FSF grows daily. Tom On 26 April 2011 16:20, paolo.carlini at oracle dot com < gcc-bugzi...@gcc.gnu.org> wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48750 > > --- Comment #9 from Paolo Carlini > 2011-04-26 15:19:12 UTC --- > Seth, Tom, if you get a chance to test the changes I propose in Comment 7 > (suitably, trivially tweaked for 4.4.x), please let me know as soon as > possible. > > If Johannes cannot provide feedback on this issue over the next few days I > mean > to go ahead with my patch, likely for 4.6.x too, and work on a other > similar > tweaks in the same spirit elsewhere in the parallel code (luckily we have > only > an handful of operator new / operator delete pairs needing attention). > > -- > Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email > --- You are receiving this mail because: --- > You are on the CC list for the bug. >