From 0284fcd5c7c42c681a37ecea15d84ba95718e788 Mon Sep 17 00:00:00 2001 From: Hui Yu Date: Sun, 10 Jan 2021 15:10:05 +0800 Subject: [PATCH] [C][Client] Fix the memory leak when a JSON string of model fails to parse. (#8390) --- .../main/resources/C-libcurl/model-body.mustache | 14 ++++++++++++++ .../client/petstore/c/.openapi-generator/VERSION | 2 +- samples/client/petstore/c/model/pet.c | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache index 0f9ec305c74..e487cb0f474 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache @@ -803,6 +803,20 @@ fail: return {{classname}}_local_var; 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; } diff --git a/samples/client/petstore/c/.openapi-generator/VERSION b/samples/client/petstore/c/.openapi-generator/VERSION index d99e7162d01..3fa3b389a57 100644 --- a/samples/client/petstore/c/.openapi-generator/VERSION +++ b/samples/client/petstore/c/.openapi-generator/VERSION @@ -1 +1 @@ -5.0.0-SNAPSHOT \ No newline at end of file +5.0.1-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/c/model/pet.c b/samples/client/petstore/c/model/pet.c index 8acdcfa132e..5ee8445640b 100644 --- a/samples/client/petstore/c/model/pet.c +++ b/samples/client/petstore/c/model/pet.c @@ -264,6 +264,10 @@ pet_t *pet_parseFromJSON(cJSON *petJSON){ return pet_local_var; end: + if (category_local_nonprim) { + category_free(category_local_nonprim); + category_local_nonprim = NULL; + } return NULL; }