[vdr] Re: cString operator= with same buffer

Holger Brunn holger.brunn at stud.uni-karlsruhe.de
Sun Nov 20 20:34:26 CET 2005

Jon Burgess on Sunday 20 November 2005 20:01:
> In the normal case you'd be correct, the destructor would be called
> twice and free up both, but in the case that the cStrings are equal the
> destructor will only be called once on the new cString. There is nothing
> which will destruct the old cString. I wrote the quick test app as
> attached and valgrind seems to agree with me.

I see, didn't think of this. So we either need also a check for equality of 
references or just forget about it completely, as both situations would be 
rather theoretical.
So could we agree on

if(&String == this) return *this;
s = String.s ? strdup(String.s) : NULL;

This will avoid the memory leak you pointed out and beahve the way you would 
expect from an assignment operator?


More information about the vdr mailing list