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] delete callback data allocated before signal emission #7840

Merged
merged 9 commits into from
Mar 21, 2018

Conversation

etherealjoy
Copy link
Contributor

@etherealjoy etherealjoy commented Mar 14, 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

Before emitting the signals declared in the API class when the callback from HTTP Worker object is received, there is memory allocation being made which is unknown to user code.

This PR adds a wrapper to any memory allocation being done and schedule deleteLater so that once the signal callback has been invoked, the object can be scheduled to be deleted.
Ideal case would be all memory allocation done by the generated code will be deallocated inside it, and user allocated memory will be done on user code.

Tests

  • PetStore
  • Docker API tests with Valgrind

There is a limitation with the current PetStore tests because when the callback is received the loop is exited which prevents deleteLater from running. So the PetStore still have the memory Leak visible.

@stkrwork @fvarose @ravinikam

@@ -21,6 +22,19 @@ namespace {{this}} {
QString stringValue(qint64 value);
QString stringValue(bool value);

template <typename ObjPtrT>
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move this class to its own file

Copy link
Contributor Author

@etherealjoy etherealjoy Mar 15, 2018

Choose a reason for hiding this comment

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

Do you want to suggest a more appropriate class name also?
I don't know if ObjLaterDeleter is appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I came up with object wrapper which is what it is..., :)

…lback_data

# Conflicts:
#	modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java
#	samples/client/petstore/qt5cpp/PetStore/PetStore.pro
{{/cppNamespaceDeclarations}}

template <typename ObjectPtrT>
class QObjectWrapper : public QObject {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also add the prefix to this class name as well

@wing328 wing328 added this to the v2.4.0 milestone Mar 21, 2018
@wing328 wing328 merged commit 3b031ed into swagger-api:master Mar 21, 2018
@etherealjoy etherealjoy deleted the qt5cpp_delete_callback_data branch March 21, 2018 18:48
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