[Marble-devel] Leak in GeoDataTrack?
Alexander Potashev
aspotashev at gmail.com
Wed May 7 15:20:54 UTC 2014
2014-05-07 18:23 GMT+04:00 Josh Knox <jknox at lauferwind.com>:
> Looks like valgrind is confusing me.
>
> The GeoDataTrack code cleans things up properly. I see that the GeoDataTrack base class, (GeoDataGeometry) destructor deletes d using a reference counting scheme and appears to work.
>
> It is not clear to me why valgrind reports it as a leak though. :(
Hi Josh,
There is a leak: when you create a GeoDataTrack object with a default
ctor, it does the following:
1. Calls default ctor of the parent class (GeoDataGeometry()), since
it has a vtable thanks for dtor being virtual, and because there is no
explicit initializer for GeoDataGeometry in GeoDataTrack().
The GeoDataGeometry() ctor writes "new GeoDataGeometryPrivate()" to
"d" and does refcounting.
2. Runs the code in GeoDataTrack().
The GeoDataTrack() ctor writes "new GeoDataTrackPrivate()" to "d" and
does not do refcounting. Because two new XxxPrivate objects are both
stored in "d", the first of them is lost and causes memory leak.
P.S. Don't take me as a C++ expert.
--
Alexander Potashev
More information about the Marble-devel
mailing list