Skip to content
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

Merged
merged 2 commits into from
Apr 2, 2018
Merged

[qt5cpp] Fix crash when API return a map container #7933

merged 2 commits into from
Apr 2, 2018

Conversation

MartinDelille
Copy link
Contributor

@MartinDelille MartinDelille commented Mar 28, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

@@ -185,9 +185,9 @@ void
QJsonObject obj = doc.object();

foreach(QString key, obj.keys()) {
qint32* val;
Copy link
Contributor

@etherealjoy etherealjoy Mar 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be {{returnBaseType}}

Copy link
Contributor

@etherealjoy etherealjoy Mar 29, 2018

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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();

Copy link
Contributor

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.

Copy link
Contributor

@etherealjoy etherealjoy left a 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.

@wing328 wing328 merged commit 23b31ab into swagger-api:master Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants