[Kstars-devel] Possible double free in skyobject

Khudyakov Alexey alexey.skladnoy at gmail.com
Sun May 31 10:47:51 CEST 2009


Hello

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)


--
  Khudyakov Alexey


More information about the Kstars-devel mailing list