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:

Qt Code:
  1. QString CfgMgr::getValue()
  2. {
  3. QString qstrValue;
  4. char* cstr = 0; // null pointer
  5. if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
  6. qstrValue = cstr; // copies the data?
  7. delete [] cstr;
  8. }
  9. return qstrValue;
  10. }
  11.  
  12. 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:

Qt Code:
  1. QString CfgMgr::getValue()
  2. {
  3. QString qstrValue;
  4. char* cstr = 0; // null pointer
  5. if (Get_Value(&cstr)){ // external call that allocates memory using 'new'
  6. QByteArray ba(cstr); // deep copy
  7. delete [] cstr;
  8. qstrValue = ba;
  9. }
  10. return qstrValue;
  11. }
  12. 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.