public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57510] New: initializer_list memory leak
@ 2013-06-03 12:23 matt at ookypooky dot com
  2013-06-03 13:09 ` [Bug c++/57510] " redi at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: matt at ookypooky dot com @ 2013-06-03 12:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57510
           Summary: initializer_list memory leak
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at ookypooky dot com

Created attachment 30247
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30247&action=edit
Code demonstrating the problem

It looks as though initializer_list can suffer from memory leaks - if during
construction of the initializer_list members an exception is thrown then the
previously allocated members are not correctly destroyed. Unfortunately I do
not have access to a newer g++ version than 4.7.2, however I could not see any
mention of this issue in the closed bugs.

Code (also attached):
--
#include <memory>
#include <random>

struct X
{
    X () : m_n (std::unique_ptr<int> (new int)) { if (random () & 1) throw 1; }
    std::unique_ptr<int> m_n;
};

void foo (std::initializer_list<X>)
{
}

int main ()
{
  for (int i = 0; i < 10; ++i)
  {
    try
    {
      foo ({ X{}, X{} });
    }
    catch (...) {}
  }
}
--

$ g++ -v
Using built-in specs.
COLLECT_GCC=/software/thirdparty/gcc/4.7.2-0.el6_64/bin/g++
COLLECT_LTO_WRAPPER=/software/thirdparty/gcc/4.7.2-0.el6_64/libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/software/thirdparty/gcc/4.7.2-0.el6_64
--with-system-zlib --enable-shared --enable-threads=posix --enable-laguages=all
Thread model: posix
gcc version 4.7.2 (GCC)

$ g++ -std=c++11 memory_leak.cpp

$ valgrind ./a.out
==13775== Memcheck, a memory error detector
==13775== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==13775== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==13775== Command: ./a.out
==13775==
==13775==
==13775== HEAP SUMMARY:
==13775==     in use at exit: 12 bytes in 3 blocks
==13775==   total heap usage: 23 allocs, 20 frees, 1,244 bytes allocated
==13775==
==13775== LEAK SUMMARY:
==13775==    definitely lost: 12 bytes in 3 blocks
==13775==    indirectly lost: 0 bytes in 0 blocks
==13775==      possibly lost: 0 bytes in 0 blocks
==13775==    still reachable: 0 bytes in 0 blocks
==13775==         suppressed: 0 bytes in 0 blocks
==13775== Rerun with --leak-check=full to see details of leaked memory
==13775==
==13775== For counts of detected and suppressed errors, rerun with: -v
==13775== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
@ 2013-06-03 13:09 ` redi at gcc dot gnu.org
  2013-06-03 14:28 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-06-03 13:09 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-06-03
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Testcase without <memory and <random> and not requiring valgrind:

#include <initializer_list>

struct counter
{
  static int n;

  counter() { ++n; }
  counter(const counter&) { ++n; }
  ~counter() { --n; }
};

int counter::n = 0;

struct X
{
    X () { if (counter::n > 1) throw 1; }

    counter c;
};

int main ()
{
  try
  {
    auto x = { X{}, X{} };
  }
  catch (...)
  {
    if ( counter::n != 0 )
      throw;
  }
}


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
  2013-06-03 13:09 ` [Bug c++/57510] " redi at gcc dot gnu.org
@ 2013-06-03 14:28 ` paolo.carlini at oracle dot com
  2013-07-22 10:42 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-03 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
           Priority|P3                          |P2
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thus I would say wrong code and P2.


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
  2013-06-03 13:09 ` [Bug c++/57510] " redi at gcc dot gnu.org
  2013-06-03 14:28 ` paolo.carlini at oracle dot com
@ 2013-07-22 10:42 ` redi at gcc dot gnu.org
  2014-12-08 21:03 ` tavianator at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2013-07-22 10:42 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mmehlich at semanticdesigns dot co
                   |                            |m

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 57930 has been marked as a duplicate of this bug. ***


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (2 preceding siblings ...)
  2013-07-22 10:42 ` redi at gcc dot gnu.org
@ 2014-12-08 21:03 ` tavianator at gmail dot com
  2014-12-10 22:25 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tavianator at gmail dot com @ 2014-12-08 21:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

--- Comment #4 from Tavian Barnes <tavianator at gmail dot com> ---
I have a testing tool that automatically inserts operator new failures, to help
test exception safety and check for leaks.  This bug causes all kinds of
spurious failures that I have to work around, since anything like this

    vector<string> vec = {"some", "strings"};

leaks memory if the second string constructor fails.  Usually it can be worked
around like this

    string arr[] = {"some", "strings"};

but it's still quite annoying.

If someone can point me in the right direction or give an outline of how to fix
this bug, I'm happy to try and write up a patch myself.  Thanks!


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (3 preceding siblings ...)
  2014-12-08 21:03 ` tavianator at gmail dot com
@ 2014-12-10 22:25 ` jason at gcc dot gnu.org
  2014-12-12  3:49 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2014-12-10 22:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (4 preceding siblings ...)
  2014-12-10 22:25 ` jason at gcc dot gnu.org
@ 2014-12-12  3:49 ` jason at gcc dot gnu.org
  2014-12-12  3:58 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2014-12-12  3:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Fri Dec 12 03:48:55 2014
New Revision: 218653

URL: https://gcc.gnu.org/viewcvs?rev=218653&root=gcc&view=rev
Log:
    PR c++/57510
    * typeck2.c (split_nonconstant_init_1): Handle arrays here.
    (store_init_value): Not here.
    (split_nonconstant_init): Look through TARGET_EXPR.  No longer static.
    * cp-tree.h: Declare split_nonconstant_init.
    * call.c (set_up_extended_ref_temp): Use split_nonconstant_init.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/initlist90.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/typeck2.c


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (5 preceding siblings ...)
  2014-12-12  3:49 ` jason at gcc dot gnu.org
@ 2014-12-12  3:58 ` jason at gcc dot gnu.org
  2015-01-23 16:31 ` jason at gcc dot gnu.org
  2020-03-10 20:10 ` [Bug c++/57510] subobjects not destroyed when exception thrown during list-initialization jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2014-12-12  3:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.0

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 5.


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

* [Bug c++/57510] initializer_list memory leak
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (6 preceding siblings ...)
  2014-12-12  3:58 ` jason at gcc dot gnu.org
@ 2015-01-23 16:31 ` jason at gcc dot gnu.org
  2020-03-10 20:10 ` [Bug c++/57510] subobjects not destroyed when exception thrown during list-initialization jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2015-01-23 16:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

--- Comment #7 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Fri Jan 23 16:30:00 2015
New Revision: 220047

URL: https://gcc.gnu.org/viewcvs?rev=220047&root=gcc&view=rev
Log:
    PR c++/64314
    PR c++/57510
    * typeck2.c (split_nonconstant_init_1): Remove a sub-CONSTRUCTOR
    that has been completely split out.

Added:
    trunk/gcc/testsuite/g++.dg/init/array38.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck2.c


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

* [Bug c++/57510] subobjects not destroyed when exception thrown during list-initialization
  2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
                   ` (7 preceding siblings ...)
  2015-01-23 16:31 ` jason at gcc dot gnu.org
@ 2020-03-10 20:10 ` jason at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2020-03-10 20:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57510

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> ---
Let's close this one and handle the remaining cases under PRs 52320 and 66139.

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

end of thread, other threads:[~2020-03-10 20:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 12:23 [Bug c++/57510] New: initializer_list memory leak matt at ookypooky dot com
2013-06-03 13:09 ` [Bug c++/57510] " redi at gcc dot gnu.org
2013-06-03 14:28 ` paolo.carlini at oracle dot com
2013-07-22 10:42 ` redi at gcc dot gnu.org
2014-12-08 21:03 ` tavianator at gmail dot com
2014-12-10 22:25 ` jason at gcc dot gnu.org
2014-12-12  3:49 ` jason at gcc dot gnu.org
2014-12-12  3:58 ` jason at gcc dot gnu.org
2015-01-23 16:31 ` jason at gcc dot gnu.org
2020-03-10 20:10 ` [Bug c++/57510] subobjects not destroyed when exception thrown during list-initialization jason 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).