On Wed, Nov 30, 2005 at 02:23:02PM +0100, Bj?rn Persson wrote:
> Should it be possible to pass a Result to a function by copy? I had a problem
> with sporadic crashes and tracked it to a function where I had accidentally
> declared a parameter as "Result" instead of "const Result&". I'm not sure
> it's ever useful to pass a Result by copy instead of by reference, but it's
> not good that it causes hard-to-track memory corruption.
>
> So which way should the bug hunt go from here? Is it a bug that passing by
> copy doesn't work, or is it good that it doesn't work but bad that it
> corrupts the memory instead of raising an exception or causing a compilation
> error?
Looks like a bug in ResUse to me. ResUse is coded in such a way that it
behaves like an auto_ptr, in the sense that only one Result or ResUse object
contains a valid result_ pointer at any given time.
The copy constructor in ResUse doesn't behave the same as operator=()
in this case. This causes purge() to misbehave in the destructors of
each copy.
Could you give the following patch a try?
- Chris
Index: lib/result.h
===================================================================
--- lib/result.h (revision 1147)
+++ lib/result.h (working copy)
@@ -82,6 +82,7 @@
initialized_(false)
{
copy(other);
+ other.result_ = 0;
}
/// \brief Destroy object