Skip to content

Commit

Permalink
Qt5cpp plug memleaks part2 (#7792)
Browse files Browse the repository at this point in the history
* Small fixes to prevent crash when empty json body is provided.

* Fix some more memory Leaks in the model-body
- Members not deleted in cleanup() method, for maps/arrays of primitive types.
- Avoid undefined behavior when updating class members with data from missing json fields
  • Loading branch information
etherealjoy authored and wing328 committed Mar 8, 2018
1 parent f00a1ef commit 1947220
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace {{this}} {

void
setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(value == nullptr) {
if((value == nullptr) || (obj.isUndefined())) {
// can't set value with a null pointer
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ void
delete o;
}{{/isContainer}}
delete {{name}};
}{{/complexType}}
}{{/complexType}}{{^complexType}}{{#isContainer}}
if({{name}} != nullptr) { {{#items.isContainer}}
auto arr = {{name}};
for(auto o: *arr) {
delete o;
}{{/items.isContainer}}
delete {{name}};
}{{/isContainer}}{{/complexType}}
{{/vars}}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/qt5cpp/client/SWGHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Swagger {

void
setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(value == nullptr) {
if((value == nullptr) || (obj.isUndefined())) {
// can't set value with a null pointer
return;
}
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/qt5cpp/client/SWGHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef SWG_HELPERS_H
#define SWG_HELPERS_H

#include <QJsonObject>
#include <QJsonValue>
#include <QList>
#include <QMap>
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/qt5cpp/client/SWGModelFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef ModelFactory_H_
#define ModelFactory_H_

#include "SWGObject.h"

#include "SWGApiResponse.h"
#include "SWGCategory.h"
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/qt5cpp/client/SWGObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#ifndef _SWG_OBJECT_H_
#define _SWG_OBJECT_H_

#include <QJsonValue>
#include <QJsonObject>

namespace Swagger {

Expand Down

0 comments on commit 1947220

Please sign in to comment.