Memleak in DOM::*::operator=( const Node & )

Marc Mutz Marc.Mutz at uni-bielefeld.de
Mon Dec 2 11:22:06 GMT 2002


Hi!

This code
  Element e = <some element>;
  // !e.isNull();
  e = Node();
  // e.isNull();

leaks one ElemImpl, since operator= in the third line doesn't deref the 
old ElemImpl:

Element &Element::operator = (const Node &other)
{
    NodeImpl* ohandle = other.handle();
    if ( impl != ohandle ) {
    if (!ohandle || !ohandle->isElementNode()) {
+       if (impl) impl->deref();
        impl = 0;
        } else {
    Node::operator =(other);
        }
    }
    return *this;
}

This bug is in at least Element and Attr, possibly in all other 
Node-derived types except Node itself. I briefly checked the Ksvg code 
and they don't seem to have downcast operators.

Another approach at fixing this is to use:

--
NodeImpl * ohandle = other.handle();
if ( ohandle && ohandle->isElementNode() )
  Node::operator=( other );
else
  Node::operator=( Node() );
return *this;
--

But that's slower ;-)

Marc

-- 
[Norton SystemWorks 2002] Wipe Info uses hexadecimal values to wipe
files. This provides more security than wiping with decimal values.
                           -- Norton SystemWorks 2002 Manual, p.160
                              (seen on Cryptogram 12/01)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20021202/e2f65520/attachment.sig>


More information about the kfm-devel mailing list