[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: kaboodle bug (Re: Problem when embedding ReadOnly parts)
From:       Björn Sahlström <kbjorn () users ! sourceforge ! net>
Date:       2002-07-19 22:43:32
[Download RAW message or body]

On Friday 19 July 2002 23.30, David Faure wrote:
> > I tried to run it and debug in KDevelop but it just crashes. I'm not so
> > used with using gdb directly but the backtrace indicates that the actual
> > crash is in KInstance::aboutData() and valgrind gives this output:
> > kbear: KBearDirLister::getPreviewPartInternal() mime in=audio/x-mp3
> > ==7679==
> > ==7679== Invalid read of size 4
> > ==7679==    at 0x4096ED06: KInstance::aboutData(void) const
> > (kinstance.cpp:175)
> > ==7679==    by 0x409706DE: KLibrary::~KLibrary(void) (klibloader.cpp:136)
>
> What does klibloader.cpp:136 say for you?
> Does it really call KInstance::aboutData() ??
>

Definitly not:
klibloader.cpp:136 -> delete m_factory;

But look at this:

KaboodleFactory::~KaboodleFactory()
{
	delete s_instance->aboutData(); <---- here is a new about data object created 
as const and deleted, not the same object as in instance()
	delete s_instance;
	s_instance = 0;
}
KInstance *KaboodleFactory::instance()
{
	if(!s_instance)
		s_instance = new KInstance(aboutData()); <-- here is an about object created 
but it's not the same as the one that's deleted in the destructor

	return s_instance;
}

const KAboutData *KaboodleFactory::aboutData()
{
	KAboutData *data = new KAboutData("kaboodle", I18N_NOOP("Kaboodle"), 
-----snip-----
	return data;
}

And in the header:

class KaboodleFactory : public KLibFactory
{
Q_OBJECT

public:
	KaboodleFactory();
	virtual ~KaboodleFactory();

	virtual QObject* createObject(QObject *parent = 0, const char *name = 0, 
const char *classname = "QObject", const QStringList &args = QStringList());

	static const KAboutData *aboutData();
	static KInstance *instance();
	
private:
	static KInstance *s_instance;
};


Shouldn't it be something like this, in the header:

private:
	static KInstance *s_instance;
	static KAboutData* *s_aboutData;

and in implementation:

const KAboutData *KaboodleFactory::aboutData()
{
	if( ! s_aboutData ) {
		s_aboutData = new KAboutData("kaboodle", I18N_NOOP("Kaboodle"), 	
	---snip---
	}
	return s_aboutData;
}



-- 
MVH
Björn Sahlström
kbjorn@users.sourceforge.net



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic