Qt5cpp plug memleaks part2 (#7792)

* 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
This commit is contained in:
etherealjoy 2018-03-08 17:19:45 +01:00 committed by William Cheng
parent f00a1ef52c
commit 1947220159
6 changed files with 13 additions and 4 deletions

View File

@ -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;
}

View File

@ -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}}
}

View File

@ -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;
}

View File

@ -13,6 +13,7 @@
#ifndef SWG_HELPERS_H
#define SWG_HELPERS_H
#include <QJsonObject>
#include <QJsonValue>
#include <QList>
#include <QMap>

View File

@ -13,6 +13,7 @@
#ifndef ModelFactory_H_
#define ModelFactory_H_
#include "SWGObject.h"
#include "SWGApiResponse.h"
#include "SWGCategory.h"

View File

@ -13,7 +13,7 @@
#ifndef _SWG_OBJECT_H_
#define _SWG_OBJECT_H_
#include <QJsonValue>
#include <QJsonObject>
namespace Swagger {