kSharedPtr access violation problem

Ralf Habacker ralf.habacker at freenet.de
Tue Sep 11 16:23:30 CEST 2007


Hi,

I encounter a access violation when running kbuildsycoca4 with msvc. For 
a description see below:

     kdecore.dll!KSharedPtr<KSharedConfig>::attach(KSharedConfig * 
p=0x00000000)  Line 203 + 0x6 bytes    C++
     kdecore.dll!KSharedPtr<KSharedConfig>::clear()  Line 211    C++
     kdecore.dll!KComponentDataPrivate::checkConfig()  Line 115 + 0xb 
bytes    C++
     kdecore.dll!KComponentDataPrivate::deref()  Line 63    C++
     kdecore.dll!KComponentData::~KComponentData()  Line 134    C++
     
kdecore.dll!KStandardDirs::KStandardDirsPrivate::~KStandardDirsPrivate()  
+ 0x7b bytes    C++
     kdecore.dll!KStandardDirs::KStandardDirsPrivate::`scalar deleting 
destructor'()  + 0x16 bytes    C++
     kdecore.dll!KStandardDirs::~KStandardDirs()  Line 353 + 0x1f 
bytes    C++
     kdecore.dll!KStandardDirs::`vector deleting destructor'()  + 0x54 
bytes    C++
     kdecore.dll!KComponentDataPrivate::checkConfig()  Line 125 + 0x22 
bytes    C++
     kdecore.dll!KComponentDataPrivate::deref()  Line 63    C++
     kdecore.dll!KComponentData::~KComponentData()  Line 134    C++
     kdecore.dll!KGlobalPrivate::~KGlobalPrivate()  Line 77 + 0x1e 
bytes    C++
     kdecore.dll!KGlobalPrivate::`scalar deleting destructor'()  + 0x16 
bytes    C++
     kdecore.dll!_k_globalData__LINE__::destroy()  Line 86 + 0x53 
bytes    C++
     kdecore.dll!KCleanUpGlobalStatic::~KCleanUpGlobalStatic()  Line 64 
+ 0x18 bytes    C++
     kdecore.dll!`_k_globalData__LINE__::operator->'::`13'::`dynamic 
atexit destructor for 'cleanUpObject''()  + 0xd bytes    C++
     kdecore.dll!_CRT_INIT(void * hDllHandle=0x00da0000, unsigned long 
dwReason=0x00000000, void * lpreserved=0x00000001)  Line 417    C
     kdecore.dll!__DllMainCRTStartup(void * hDllHandle=0x00da0000, 
unsigned long dwReason=0x00000000, void * lpreserved=0x00000001)  Line 
509 + 0x11 bytes    C
     kdecore.dll!_DllMainCRTStartup(void * hDllHandle=0x00da0000, 
unsigned long dwReason=0x00000000, void * lpreserved=0x00000001)  Line 
459 + 0x11 bytes    C
     ntdll.dll!7c9111a7()    
     [Frames below may be incorrect and/or missing, no symbols loaded 
for ntdll.dll]   
     ntdll.dll!7c933f31()    
     ntdll.dll!7c920945()    
     ntdll.dll!7c92094e()    
     kernel32.dll!7c81cd76()    
     ntdll.dll!7c91f0aa()    
     kernel32.dll!7c80e62b()    
     kernel32.dll!7c80e45c()    
     kernel32.dll!7c81cdee()    
     msvcr80d.dll!10202289()    
     msvcr80d.dll!10202124()    
     msvcr80d.dll!10201e00()    
     kbuildsycoca4.exe!__tmainCRTStartup()  Line 599    C
     kbuildsycoca4.exe!mainCRTStartup()  Line 403    C
     kernel32.dll!7c816fd7()    



void KComponentDataPrivate::checkConfig()
{
    if (syncing) {
        return;
    }
    if (sharedConfig.isUnique()) {
        if (refCount == 1) {
            if (!syncing) {
                syncing = true;
                sharedConfig->sync(); // sync before KComponentData 
doesn't have a KSharedConfig
                                      // object anymore
                syncing = false;
            }
!!!!!!!            sharedConfig.clear(); // will delete sharedConfig and 
then deref this to 0
        } else if (refCount == 2 && dirs) { // KStandardDirs holds a ref 
to us
            if (!syncing) {
                syncing = true;
                sharedConfig->sync(); // sync before KComponentData 
doesn't have a KSharedConfig
                                      // object anymore
                syncing = false;
            }
            KStandardDirs *tmp = dirs;
            dirs = 0;
            delete tmp; // calls deref()
        }
    }
}

template <class T>
Q_INLINE_TEMPLATE void KSharedPtr<T>::clear()
{
    attach(static_cast<T*>(0));
}


template <class T>
Q_INLINE_TEMPLATE void KSharedPtr<T>::attach(T* p)
{
    if (d != p) {
        if (p) p->ref.ref();
        if (d && !d->ref.deref())
            delete d;
  !!!!!       d = p;
    }
}

The write access violation occurs in the line marked with !!!!

After deleting d the assignment d = p (where p = 0) fails, d is not 
accessable. If I try to dump the memory under this, it is not accessable.
Does anyone have an idea what's going wrong ?

Ralf







More information about the Kde-windows mailing list