Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I took a look to
https://scan5.coverity.com:8443/reports.htm#v22002/p10276/fileInstanceId=47958646&defectInstanceId=14481124&mergedDefectId=708945
 32class SbxVarEntry : public SbxVariableRef {
 33public:
 34    OUString* pAlias;
 35    SbxVarEntry() : SbxVariableRef(), pAlias( NULL ) {}
  
CID 708945 (#1 of 1): Non-virtual destructor (VIRTUAL_DTOR)1.
nonvirtual_dtor: Class SbxVarEntry has a destructor and a pointer to it is
upcast to class SbxVariableRef which doesn't have a virtual destructor.
 36   ~SbxVarEntry() { delete pAlias; }
 37};

Indeed SbxVariableRef is defined via macro SV_DECL_REF (see
http://opengrok.libreoffice.org/xref/core/include/tools/ref.hxx#73), here's
some unwinding

SV_DECL_REF
     73 #define SV_DECL_REF( ClassName )                \
     74 class ClassName;                                \
     75 class ClassName##Ref                            \
     76 {                                               \
     77     PRV_SV_DECL_REF( ClassName )                \
     78 };

     70 #define PRV_SV_DECL_REF( ClassName )            \
     71 PRV_SV_DECL_REF_LOCK( ClassName, Ref )   

     53 #define PRV_SV_DECL_REF_LOCK(ClassName, Ref)    \
     54 protected:                                      \
     55     ClassName * pObj;                           \
     56 public:                                         \
     57     inline               ClassName##Ref() { pObj = 0; }                
\
     58     inline               ClassName##Ref( const ClassName##Ref & rObj
); \
     59     inline               ClassName##Ref( ClassName * pObjP );          
\
     60     inline void          Clear();                                      
\
     61     inline               ~ClassName##Ref();                            
\
     62     inline ClassName##Ref & operator = ( const ClassName##Ref & rObj
); \
     63     inline ClassName##Ref & operator = ( ClassName * pObj );           
\
     64     inline sal_Bool        Is() const { return pObj != NULL; }         
\
     65     inline ClassName *     operator &  () const { return pObj; }       
\
     66     inline ClassName *     operator -> () const { return pObj; }       
\
     67     inline ClassName &     operator *  () const { return *pObj; }      
\
     68     inline operator ClassName * () const { return pObj; }

So indeed, there's no virtual destructor, therefore ~SbxVarEntry can't be
called.

SV_DECLR_REF is called a lot of times (see
http://opengrok.libreoffice.org/search?q=SV_DECL_REF&project=core&defs=&refs=&path=&hist=)
so I don't know if "virtual" keyword should just be added to the macro or
should we declare SbxVariableRef without this macro.
I didn't check the other classes which use this macro but it could be mean
other cases (destructor not called) like this.

Any suggestion?

Julien



--
View this message in context: 
http://nabble.documentfoundation.org/LO-scan-coverity-708945-non-virtual-destructor-in-parent-class-tp4087082.html
Sent from the Dev mailing list archive at Nabble.com.

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.