[PATCH] kdelibs: Memory leaks (d-pointer not deleted) fixed

Benjamin Meyer ben at meyerhome.net
Fri Dec 31 05:07:14 GMT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 28 October 2004 2:58 pm, Thiago Macieira wrote:
> Andrew Coles wrote:
> >On Thursday 28 Oct 2004 12:18, Thiago Macieira wrote:
> >>There's also the case of KCharSelect, in which the destructor is now
> >> added, instead of the implicit one. That doesn't break binary
> >> compatibility, but old code will not see the improvement.
> >
> >Just looking at KCharSelect, is there a good reason why it isn't:
> >
> >KCharSelectPrivate* const d;
> >
> >instead of
> >
> >KCharSelectPrivate *d;
> >
> >and then initialise d using the initialisation syntax instead of as the
> > first line of the constructor, i.e.
> >
> > ... QVBox( parent, name ), d(new KCharSelectPrivate) {
> >
> >instead of
> >
> > ... QVBox( parent, name ) {
> >    d = new KCharSelectPrivate;
> >
> >If my understanding of const-based optimisations is correct, this would be
> >more efficient as the class methods could assume that the pointer d hasn't
> >changed between references to it.
>
> That's correct. The implementation is more efficient

I don't think so.  It is actually slower according using gcc 3.3 without 
optimizations.  But it will catch silly mistakes which far outweighs that.

> , since the d pointer 
> cannot change during the existence of the class.
>
> However, that doesn't change the fact that it leaks or that the fix won't
> be seen by old code.

Would this be something to be added to the KDELIBS todo list for KDE 4?

* Change all FooPrivate *d; -> FooPrivate const *d; and place initialization 
in constructor.

- -Benjamin Meyer

- -- 
aka icefox
Public Key: http://www.icefox.net/public_key.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFB1N6C1rZ3LTw38vIRAgtyAJ9o2DrwfJFkFBMBTF8uoR188fOM2ACdFKBP
6hRVLPMiTQeYY/Q7Us3AkO8=
=W3bG
-----END PGP SIGNATURE-----




More information about the kde-core-devel mailing list