New shared pointer - revision 2

Thiago Macieira thiago at kde.org
Sat Sep 10 04:10:26 BST 2005


Thiago Macieira wrote:
>The code path is this:
>                        KSharedData *x = new KSharedData;
>                        x = qAtomicSetPtr( &d, x );
>                        rhs.d->ref.ref();
>                        deref();
>                        KSharedData *x = rhs.d;
>                        x = qAtomicSetPtr( &d, x );

In fact, since d->ref was never set to 1, when deref() is called, d->ref 
will become -1, and that's not a valid value for a refcount. And there 
will be memory leak, since the object allocated on the first line will 
never be deleted.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

5. Swa he géanhwearf tó timbran, and hwonne he cóm, lá! Unix cwæð "Hello, 
World". Ǽfre ǽghwilc wæs glæd and seo woruld wæs fréo.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050910/be54c70e/attachment.sig>


More information about the kde-core-devel mailing list