public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/48750] New: for_each_template_random_access_ed has unbalanced new/delete[]
@ 2011-04-24 11:46 bugs at sehe dot nl
  2011-04-24 11:51 ` [Bug libstdc++/48750] " bugs at sehe dot nl
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: bugs at sehe dot nl @ 2011-04-24 11:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48750

           Summary: for_each_template_random_access_ed has unbalanced
                    new/delete[]
           Product: gcc
           Version: 4.4.4
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bugs@sehe.nl


thread_results is allocated using scalar new, yet deleted with array delete[]

Version of libs (ubuntu package): libstdc++6-4.4-dev through libstdc++6-4.6-dev
Version of compiler: g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Also with: g++ (Debian 4.5.2-8) 4.5.2

Snippets:
/usr/include/c++/4.4/parallel/par_loop.h:87
#   pragma omp single
{
        num_threads = omp_get_num_threads();
        thread_results = static_cast<Result*>(
                            ::operator new(num_threads * sizeof(Result)));
        constructed = new bool[num_threads];
}

but line 127:

    delete[] thread_results;

This is unbalanced, and leads to the expected valgrind errors. Attached is a
snippet (originally from
http://stackoverflow.com/questions/5769908/unexpected-segfault-with-gnu-parallelaccumulate)
that will segfault.

I witnessed the segfault went away when fixing the `delete[]` into `delete`.
However, I think it should be evaluated whether the optimized (uninitializing)
allocation of thread_results is safe to do (valgrind keeps reporting
uninitialized memory references even if the attached example doesn't segfault
anymore).

---- 

I'll attach the sources in 10 minutes due to time restriction and browser
flakiness


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2011-05-03 18:12 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-24 11:46 [Bug libstdc++/48750] New: for_each_template_random_access_ed has unbalanced new/delete[] bugs at sehe dot nl
2011-04-24 11:51 ` [Bug libstdc++/48750] " bugs at sehe dot nl
2011-04-24 12:11 ` paolo.carlini at oracle dot com
2011-04-24 12:16 ` paolo.carlini at oracle dot com
2011-04-24 12:22 ` paolo.carlini at oracle dot com
2011-04-24 12:26 ` paolo.carlini at oracle dot com
2011-04-24 12:54 ` bugs at sehe dot nl
2011-04-24 21:52 ` paolo.carlini at oracle dot com
2011-04-24 22:14 ` paolo.carlini at oracle dot com
2011-04-26 15:21 ` paolo.carlini at oracle dot com
2011-04-26 18:09 ` t.h.shorrock at gmail dot com
2011-04-26 18:40 ` paolo.carlini at oracle dot com
2011-04-26 18:40 ` paolo.carlini at oracle dot com
2011-04-27  0:57 ` paolo.carlini at oracle dot com
2011-04-27  1:09 ` paolo.carlini at oracle dot com
2011-04-27  9:53 ` bugs at sehe dot nl
2011-04-27 11:17 ` bugs at sehe dot nl
2011-04-27 20:00 ` singler at gcc dot gnu.org
2011-04-27 20:26 ` paolo.carlini at oracle dot com
2011-04-28 16:40 ` rguenth at gcc dot gnu.org
2011-05-03 14:23 ` paolo at gcc dot gnu.org
2011-05-03 15:58 ` bugs at sehe dot nl
2011-05-03 18:03 ` paolo.carlini at oracle dot com
2011-05-03 18:12 ` paolo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).