[C][Client] Fix the memory leak when a JSON string of model fails to parse. (#8390)

This commit is contained in:
Hui Yu 2021-01-10 15:10:05 +08:00 committed by GitHub
parent f136b9fd01
commit 0284fcd5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -803,6 +803,20 @@ fail:
return {{classname}}_local_var; return {{classname}}_local_var;
end: end:
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{^isEnum}}
if ({{{name}}}_local_nonprim) {
{{complexType}}_free({{{name}}}_local_nonprim);
{{{name}}}_local_nonprim = NULL;
}
{{/isEnum}}
{{/isModel}}
{{/isPrimitiveType}}
{{/isContainer}}
{{/vars}}
return NULL; return NULL;
} }

View File

@ -1 +1 @@
5.0.0-SNAPSHOT 5.0.1-SNAPSHOT

View File

@ -264,6 +264,10 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){
return pet_local_var; return pet_local_var;
end: end:
if (category_local_nonprim) {
category_free(category_local_nonprim);
category_local_nonprim = NULL;
}
return NULL; return NULL;
} }