-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[qt5cpp] Fix crash when API return a map container #7933
[qt5cpp] Fix crash when API return a map container #7933
Conversation
@@ -185,9 +185,9 @@ void | |||
QJsonObject obj = doc.object(); | |||
|
|||
foreach(QString key, obj.keys()) { | |||
qint32* val; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be {{returnBaseType}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of this PR, but in case the {{returnBaseType}} is dynamically allocated (Object, QString,QDateTime,QbyteArray ... etc ), it has to be wrapped with QObjectWrapper for later deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you tell me more about QObjectWrapper? I never used it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, it is a template class which holds the pointer to the memory allocated for dynamically allocated types like QString, Object, QByteArray etc.., for the parameter to be passed in the slot callback. In this file you can find it being used, so once the signal is emitted and the slot activated, the deleteLater ensures the object is deleted after the process event has finished.
Present in the template QObjectWrapper.mustache
auto objwrapper = new {{prefix}}QObjectWrapper<{{{returnBaseType}}}*> (o);
objwrapper->deleteLater();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I mentioned, it is not part of the crash, but simply to avoid memory leaks for complex types. If you have the time it is a good thing to add, to remove memory leaks. But for the qt5cpp petstore example the cleanup is not working because the loop is exited on receiving the callback. In a real qt application the event loop would still be running and the object deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me for solving the crash.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Description of the PR
The client was crashing during the callback with a map container. This was due to an initialized pointer passed to the setValue method.
@ravinikam @stkrwork @fvarose @etherealjoy