Solved crash at Qt5Cored!QString::operator=
-
I have the code as below:
bool CloudResponseParser::parseAuthorizeResultToAppAccess( const QJsonObject &response, Cortex::Model::AppAccess &appAccess) { appAccess.accessToken = response["access_token"].toString(); appAccess.refreshToken = response["refresh_token"].toString(); appAccess.expireTime = currentDateTime().addSecs(response["expires_in"].toInt()); appAccess.applicationId = response["app_id"].toString(); appAccess.applicationVersion = response["app_version"].toString(); QJsonObject jsonLicenseAgreement = response["license_agreement"].toObject(); if (!jsonLicenseAgreement.isEmpty()) { if (jsonLicenseAgreement.contains("accepted")) { appAccess.licenseAgreementAccepted = jsonLicenseAgreement["accepted"].toBool(); appAccess.licenseUrl = jsonLicenseAgreement["license_url"].toString(); } } appAccess.licenseId = response["license"].toObject()["license_id"].toString(); appAccess.licenseBundle = response["license"].toObject()["current_bundle_id"].toString(); return true; }
Sometimes, or more exactly rarely, I got the crash with the stack trace:
STACK_TEXT: 00000065`480fafb0 00007ff8`a56fef5d : 00000000`00000050 00000065`480fb0f0 0000021c`759d0101 00007ff8`a5c713b6 : Qt5Cored!std::swap<QTypedArrayData<unsigned short> * __ptr64,void>+0x18 00000065`480faff0 00007ff8`a5700e10 : 00000000`00000050 00000065`480fb0f0 00000000`00000001 0000021c`750e7c00 : Qt5Cored!qSwap<QTypedArrayData<unsigned short> * __ptr64>+0x1d 00000065`480fb020 00007ff6`b69325c3 : 00000000`00000050 00000065`480fb0f0 00000065`480fb078 00007ff8`00000000 : Qt5Cored!QString::operator=+0x20 00000065`480fb050 00007ff6`b5e3bd36 : 00000065`484ffa48 00000065`480fb940 00000000`00000000 00007ff8`a57092ad : CortexService!Cortex::Cloud::CloudResponseParser::parseAuthorizeResultToAppAccess+0xa3 00000065`480fb2f0 00007ff6`b5e33996 : 00000065`484ffa38 00000000`00000000 00000065`480fb940
I did every way to check
response
andappAccess
params, they refers to a non-null object. I don't know in which cases, I will get crash atQString::operator=+
. Any advice?Thanks a lot!
-
Are there multiple threads involved? Is this method called in by multiple threads? You can check is thread sanitizer will have any warnings about it.
Do you use QStringBuilder? (either by include or by define
DEFINES *= QT_USE_QSTRINGBUILDER
)? -
@thamht4190 said in crash at Qt5Cored!QString::operator=+:
QString::operator=+
If I read the stack trace correctly, it's
QString::operator=
and+0x20
is an address offset.I have no idea what causes the crash, though.
Regards
-
Are there multiple threads involved? Is this method called in by multiple threads?
@sierdzio My application is multi thread, so I was afraid too. However, I checked very carefully that
response
andappAccess
are accessed by only one thread.CloudResponseParser::parseAuthorizeResultToAppAccess(response, appAccess)
is called only on this thread.Do you use QStringBuilder? (either by include or by define DEFINES *= QT_USE_QSTRINGBUILDER)?
No, I don't use it.
-
@aha_1980 Yes, you're right. I updated the title.
-
appAccess
is passed by (non-const) reference. Does that object live in the same thread asCloudResponseParser
?Sorry for asking about this gain, but since you have a code that only sometimes fails I'm pretty sure threads are to blame. We just need to find where and how.
-
Not necessarily (although rather likely), one can pass a dangling reference (e.g. a temporary object).
@thamht4190, please also provide the line where you invoke that method and how the objects that are passed came to be and how they're destroyed.
PS. Also please provide a full backtrace. This doesn't say where the call originated. Is this a static method called from
main()
? -
Thanks all. Finally I can find out why I have this crash. All of you are right about
appAccess
which has been null before passing intoCloudResponseParser::parseAuthorizeResultToAppAccess
function. I didn't know that before because I read the wrong stack trace.
Thanks again for all of your support.