[Kstars-devel] Possible double free in skyobject

Akarsh Simha akarshsimha at gmail.com
Sun May 31 12:51:06 CEST 2009


> I've just found a problem in SkyObject. It's possible to have double free in 
> the destructor. If object is copied and has auxInfo then both object will 
> share same pointer to auxInfo. After destruction of one object second will 
> hold pointer to already destroyed object which is problem on its own. When 
> destroyed it will delete again leading to double free.
> 
> > SkyObject::SkyObject( SkyObject &o ) : SkyPoint( o ) {                   
> >     setType( o.type() );                                                 
> >     Magnitude = o.mag();                                                 
> >     setName(o.name());                                                   
> >     setName2(o.name2());                                                 
> >     setLongName(o.longname());                                           
> >     info = NULL;                                                         
> >     if( o.hasAuxInfo() ) {                                               
> >         info = getAuxInfo();                                             
> >         info->ImageList = o.ImageList();                                 
> >         info->ImageTitle = o.ImageTitle();                               
> >         info->InfoList = o.InfoList();                                   
> >         info->InfoTitle = o.InfoTitle();                                 
> >         info->userLog = o.userLog();                                     
> >     }                                                                    
> > }   
> 
> Proposed solution - use QSharedDataPointer to hold data. With that we get 
> implicit data sharing for free. Explicit copy constructor is not needed, 
> default will do just fine. (And it doen't make much sense to have custom copy 
> ctor and no custom assignment operator anyway)

Hmm... I'm okay with this proposal. I don't think we have a situation
in KStars where we write different data to two copies of a SkyObject.

Regards
Akarsh


More information about the Kstars-devel mailing list