public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-10-31  9:21 bkoz
  0 siblings, 0 replies; 6+ messages in thread
From: bkoz @ 2002-10-31  9:21 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, vwhite

Synopsis: STL container can fault at runtime destroying contained objects with virtual destructors

State-Changed-From-To: feedback->open
State-Changed-By: bkoz
State-Changed-When: Thu Oct 31 09:21:09 2002
State-Changed-Why:
    Just adding this bit.
    
    Without a test case, this bug report is so sufficiently vague as to be eligible for suspension.
    
    As an aid to you, I've provided a sample test case. It doesn't core. However, without the required copy constructor (vector requires all contained types to be both copyconstrible and assignable) you'll get a core. Perhaps this is what you are seeing?
    
    -benjamin
    
    #include <new>
    #include <vector>
    
    struct base
    {
    protected: 
      int i;
      char* p;
    
    public:
      base(int j = 0, const char* name = "hush hush"): i(j)
      {
        p = new char[strlen(name) + 1];
        strcpy(p, name);
      }
    
      ~base()
      { delete [] p; }
    };
    
    struct derived: public base
    {
      derived(int j2 = 5, const char* name2 = "mush mush"): base(j2, name2) { }
    
    #if 0
      // Define to make conformant to vector requirements.
      derived(const derived& dup)
      {
        i = dup.i;
        delete [] p;
        p = new char[strlen(dup.p) + 1];
        strcpy(p, dup.p);
      }
    
      derived&
      operator=(const derived& dup)
      {
        i = dup.i;
        delete [] p;
        p = new char[strlen(dup.p) + 1];
        strcpy(p, dup.p);
        return *this;
      }
    #endif
    };
    
    int main()
    {
      // Must be copyconstructible and assignable.
      std::vector<derived> vec(6);
      vec.push_back(derived(3, "blow up"));
      return 0;
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8359


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

* Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-11-19 12:26 bkoz
  0 siblings, 0 replies; 6+ messages in thread
From: bkoz @ 2002-11-19 12:26 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, vwhite

Synopsis: STL container can fault at runtime destroying contained objects with virtual destructors

State-Changed-From-To: feedback->closed
State-Changed-By: bkoz
State-Changed-When: Mon Nov 11 15:04:26 2002
State-Changed-Why:
    No feedback.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8359


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

* Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-11-01  8:39 bkoz
  0 siblings, 0 replies; 6+ messages in thread
From: bkoz @ 2002-11-01  8:39 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, vwhite

Synopsis: STL container can fault at runtime destroying contained objects with virtual destructors

State-Changed-From-To: open->feedback
State-Changed-By: bkoz
State-Changed-When: Fri Nov  1 08:39:01 2002
State-Changed-Why:
    Awaiting a test case.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8359


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

* RE: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-10-28 11:16 Victor White
  0 siblings, 0 replies; 6+ messages in thread
From: Victor White @ 2002-10-28 11:16 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR libstdc++/8359; it has been noted by GNATS.

From: "Victor White" <VWhite@entercept.com>
To: <paolo@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<gcc-gnats@gcc.gnu.org>
Cc:  
Subject: RE: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
Date: Mon, 28 Oct 2002 11:07:10 -0800

 I'll see if we can come up with one.
 
 -----Original Message-----
 From: paolo@gcc.gnu.org [mailto:paolo@gcc.gnu.org]
 Sent: Sunday, October 27, 2002 1:30 PM
 To: gcc-bugs@gcc.gnu.org; gcc-prs@gcc.gnu.org; nobody@gcc.gnu.org;
 Victor White
 Subject: Re: libstdc++/8359: STL container can fault at runtime
 destroying contained objects with virtual destructors
 
 
 Synopsis: STL container can fault at runtime destroying contained =
 objects with virtual destructors
 
 State-Changed-From-To: open->feedback
 State-Changed-By: paolo
 State-Changed-When: Sun Oct 27 13:29:35 2002
 State-Changed-Why:
     You really should strive to provide a short self-contained
     testcase...
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=3Dview%20audit-trail&database=3D=
 gcc&pr=3D8359


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

* Re: libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-10-27 13:29 paolo
  0 siblings, 0 replies; 6+ messages in thread
From: paolo @ 2002-10-27 13:29 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, vwhite

Synopsis: STL container can fault at runtime destroying contained objects with virtual destructors

State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Sun Oct 27 13:29:35 2002
State-Changed-Why:
    You really should strive to provide a short self-contained
    testcase...

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8359


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

* libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors
@ 2002-10-25 13:06 vwhite
  0 siblings, 0 replies; 6+ messages in thread
From: vwhite @ 2002-10-25 13:06 UTC (permalink / raw)
  To: gcc-gnats


>Number:         8359
>Category:       libstdc++
>Synopsis:       STL container can fault at runtime destroying contained objects with virtual destructors
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 25 13:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Victor  White, for D. Hosterman
>Release:        "gcc (GCC) 3.2 20020708 (experimental)" with "libstdc++-v3"
>Organization:
>Environment:
HP PA2.0 hardware (compiling PA1.1 code), HP-UX 11i
>Description:
The standard template library file

    include/c++/3.2/bits/stl_construct.h

includes a definition of the following template function:

    template <class _Tp>
      inline void
      _Destroy(_Tp* __pointer)
      { __pointer->~_Tp(); }

The function will be called when destroying
an element of a container (vector, list, etc.).
If that element is a derived object with virtual
destructors, it can end up calling an incorrect
sequence of destructors which (on my system) results
in a SIGSEGV when an object is removed from the
container.

>How-To-Repeat:
Sorry, I don't happen to have a canned example.  This
appeared in a very large program we are working on
which I have not included.

Depends on the program.  It must use a container
that holds the object itself (not a pointer to).
The object must be a derived type with a virtual
destructor.

>Fix:
The change made locally was:

    template <class _Tp>
      inline void
      _Destroy(_Tp* __pointer)
      { __pointer->_Tp::~_Tp(); } //<= only our destructor

Which seems to both make sense and fix the problem.

We have not yet checked to see if there are other places
in which destructors are being explicitly called that may
have similar issues.
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-11-11 23:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-31  9:21 libstdc++/8359: STL container can fault at runtime destroying contained objects with virtual destructors bkoz
  -- strict thread matches above, loose matches on Subject: below --
2002-11-19 12:26 bkoz
2002-11-01  8:39 bkoz
2002-10-28 11:16 Victor White
2002-10-27 13:29 paolo
2002-10-25 13:06 vwhite

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).