Topic: Help! ios question


Author: jaf3@ritz.cec.wustl.edu (John Andrew Fingerhut)
Date: 26 Sep 1994 14:48:28 -0500
Raw View
Nobody answered my previous post, so I thought I'd shorten it and ask
again.  I found out using purify that the ios destructor is attempting
to access the streambuf * passed in the init function.  In every solution
that I have attempted, the streambuf is destroyed prior to the ios, so
the ios destructor is accessing an object that has already been destroyed.
I have followed the class layout as suggested in a paper taken from a
paper by Jerry Schwarz.  It looks like this:

class mybuf : public streambuf {
};

class mybase : virtual public ios {
 mybuf *buf;
public:
 mybase () { buf = new mybuf; init (buf); }
 ~mybase () { delete buf; }
}

class mystream : public mybase, public ostream {
};

As you can see, when the mystream gets destroyed, the mybase destructor
is called before the ios destructor.  When the ios destructor attempts
to access the streambuf * it received in ios::init, Purify flags it as
a free memory read.

My question is: is this a quality of implementation issue or does the
standard specify more than the public interface of these classes?  I
need to know if I should be contacting Sun or not.

Stephen Gevers
sg3235@shelob.sbc.com




Author: jaf3@ritz.cec.wustl.edu (John Andrew Fingerhut)
Date: 27 Sep 1994 08:05:22 -0500
Raw View
In article <3678ic$qnj@ritz.cec.wustl.edu>,
John Andrew Fingerhut <sg3235@shelob.sbc.com> wrote:
]Nobody answered my previous post, so I thought I'd shorten it and ask
]again.  I found out using purify that the ios destructor is attempting
]to access the streambuf * passed in the init function.  In every solution
]that I have attempted, the streambuf is destroyed prior to the ios, so
]the ios destructor is accessing an object that has already been destroyed.
]I have followed the class layout as suggested in a paper taken from a
]paper by Jerry Schwarz.  It looks like this:
]
]class mybuf : public streambuf {
]};
]
]class mybase : virtual public ios {
] mybuf *buf;
]public:
] mybase () { buf = new mybuf; init (buf); }
] ~mybase () { delete buf; }
]}
]
]class mystream : public mybase, public ostream {
]};
]
]As you can see, when the mystream gets destroyed, the mybase destructor
]is called before the ios destructor.  When the ios destructor attempts
]to access the streambuf * it received in ios::init, Purify flags it as
]a free memory read.
]
]My question is: is this a quality of implementation issue or does the
]standard specify more than the public interface of these classes?  I
]need to know if I should be contacting Sun or not.
]
]Stephen Gevers
]sg3235@shelob.sbc.com

Sun's C++ 4.0.1 compiler does dot exhibit this problem...therefore, I
assume that it is a problem with their cfront based compiler.

Stephen Gevers
sg3235@shelob.sbc.com