Hello,
In the application I'm working on, i've got a class CfgMgr with a method: getValue() that's supposed to return a QString:
{
char* cstr = 0; // null pointer
if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
qstrValue = cstr; // copies the data?
delete [] cstr;
}
return qstrValue;
}
QString myValue
= CfgMgr
::getValue();
QString CfgMgr::getValue()
{
QString qstrValue;
char* cstr = 0; // null pointer
if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
qstrValue = cstr; // copies the data?
delete [] cstr;
}
return qstrValue;
}
QString myValue = CfgMgr::getValue();
To copy to clipboard, switch view to plain text mode
This works fine most of the time, but sometimes the application segfaults at qatomic_i386.h:80 after coming from QString:perator=(..)
I suspect that the problem is one of dangling pointers. I tried doing the following since QByteArray supposedly performs a deep copy:
{
char* cstr = 0; // null pointer
if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
delete [] cstr;
qstrValue = ba;
}
return qstrValue;
}
QString myValue
= CfgMgr
::getValue();
QString CfgMgr::getValue()
{
QString qstrValue;
char* cstr = 0; // null pointer
if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
QByteArray ba(cstr); // deep copy
delete [] cstr;
qstrValue = ba;
}
return qstrValue;
}
QString myValue = CfgMgr::getValue();
To copy to clipboard, switch view to plain text mode
Unfortunately, this does not seem to work either. This might just be the symptom of a problem created elsewhere but it's not unlikely that i've made a mistake here either.
Does anyone see any obvious errors ?
Any help would be greatly appreciated.
Bookmarks