diff --git a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache index a80a14d812e5..f60e66f0f226 100644 --- a/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/C-libcurl/api-body.mustache @@ -194,7 +194,7 @@ end: // header parameters char *keyHeader_{{{paramName}}} = NULL; - {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueHeader_{{{paramName}}}; + {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueHeader_{{{paramName}}} = 0; keyValuePair_t *keyPairHeader_{{paramName}} = 0; if ({{paramName}}) { keyHeader_{{{paramName}}} = strdup("{{{baseName}}}"); @@ -243,12 +243,12 @@ end: // form parameters {{#isFile}} char *keyForm_{{paramName}} = NULL; - {{{dataType}}} valueForm_{{paramName}}; + {{{dataType}}} valueForm_{{paramName}} = 0; keyValuePair_t *keyPairForm_{{paramName}} = 0; {{/isFile}} {{^isFile}} char *keyForm_{{paramName}} = NULL; - {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}}; + {{#isPrimitiveType}}{{#isNumber}}{{{dataType}}}{{/isNumber}}{{#isLong}}{{{dataType}}}{{/isLong}}{{#isInteger}}{{{dataType}}}{{/isInteger}}{{#isDouble}}{{{dataType}}}{{/isDouble}}{{#isFloat}}{{{dataType}}}{{/isFloat}}{{#isBoolean}}{{dataType}}{{/isBoolean}}{{#isEnum}}{{#isString}}{{projectName}}_{{operationId}}_{{baseName}}_e{{/isString}}{{/isEnum}}{{^isEnum}}{{#isString}}{{{dataType}}} *{{/isString}}{{/isEnum}}{{#isByteArray}}{{{dataType}}}{{/isByteArray}}{{#isDate}}{{{dataType}}}{{/isDate}}{{#isDateTime}}{{{dataType}}}{{/isDateTime}}{{#isFile}}{{{dataType}}}{{/isFile}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{^isEnum}}{{{dataType}}}_t *{{/isEnum}}{{/isModel}}{{^isModel}}{{#isEnum}}{{datatypeWithEnum}}_e{{/isEnum}}{{/isModel}}{{#isUuid}}{{dataType}} *{{/isUuid}}{{#isEmail}}{{dataType}}{{/isEmail}}{{/isPrimitiveType}} valueForm_{{paramName}} = 0; keyValuePair_t *keyPairForm_{{paramName}} = 0; {{/isFile}} if ({{paramName}} != NULL) @@ -403,7 +403,10 @@ end: free(keyHeader_{{{paramName}}}); keyHeader_{{{paramName}}} = NULL; } - free(valueHeader_{{{paramName}}}); + if (valueHeader_{{{paramName}}}) { + free(valueHeader_{{{paramName}}}); + valueHeader_{{{paramName}}} = NULL; + } {{/isString}} {{^isString}} if (keyHeader_{{{paramName}}}) { @@ -483,7 +486,10 @@ end: free(keyForm_{{{paramName}}}); keyForm_{{{paramName}}} = NULL; } - free(valueForm_{{{paramName}}}); + if (valueForm_{{{paramName}}}) { + free(valueForm_{{{paramName}}}); + valueForm_{{{paramName}}} = NULL; + } free(keyPairForm_{{paramName}}); {{/isString}} {{^isString}} @@ -523,7 +529,10 @@ end: free(keyHeader_{{{paramName}}}); keyHeader_{{{paramName}}} = NULL; } - free(valueHeader_{{{paramName}}}); + if (valueHeader_{{{paramName}}}) { + free(valueHeader_{{{paramName}}}); + valueHeader_{{{paramName}}} = NULL; + } {{/isString}} {{^isString}} if (keyHeader_{{{paramName}}}) { @@ -600,7 +609,10 @@ end: free(keyForm_{{{paramName}}}); keyForm_{{{paramName}}} = NULL; } - free(valueForm_{{{paramName}}}); + if (valueForm_{{{paramName}}}) { + free(valueForm_{{{paramName}}}); + valueForm_{{{paramName}}} = NULL; + } keyValuePair_free(keyPairForm_{{{paramName}}}); {{/isString}} {{^isString}} diff --git a/samples/client/petstore/c/api/PetAPI.c b/samples/client/petstore/c/api/PetAPI.c index 75043dcf9a1a..28aab6c189db 100644 --- a/samples/client/petstore/c/api/PetAPI.c +++ b/samples/client/petstore/c/api/PetAPI.c @@ -155,7 +155,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key ) // header parameters char *keyHeader_api_key = NULL; - char * valueHeader_api_key; + char * valueHeader_api_key = 0; keyValuePair_t *keyPairHeader_api_key = 0; if (api_key) { keyHeader_api_key = strdup("api_key"); @@ -195,7 +195,10 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId , char * api_key ) free(keyHeader_api_key); keyHeader_api_key = NULL; } - free(valueHeader_api_key); + if (valueHeader_api_key) { + free(valueHeader_api_key); + valueHeader_api_key = NULL; + } free(keyPairHeader_api_key); } @@ -554,7 +557,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char // form parameters char *keyForm_name = NULL; - char * valueForm_name; + char * valueForm_name = 0; keyValuePair_t *keyPairForm_name = 0; if (name != NULL) { @@ -566,7 +569,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char // form parameters char *keyForm_status = NULL; - char * valueForm_status; + char * valueForm_status = 0; keyValuePair_t *keyPairForm_status = 0; if (status != NULL) { @@ -607,13 +610,19 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId , char * name , char free(keyForm_name); keyForm_name = NULL; } - free(valueForm_name); + if (valueForm_name) { + free(valueForm_name); + valueForm_name = NULL; + } keyValuePair_free(keyPairForm_name); if (keyForm_status) { free(keyForm_status); keyForm_status = NULL; } - free(valueForm_status); + if (valueForm_status) { + free(valueForm_status); + valueForm_status = NULL; + } keyValuePair_free(keyPairForm_status); } @@ -654,7 +663,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata // form parameters char *keyForm_additionalMetadata = NULL; - char * valueForm_additionalMetadata; + char * valueForm_additionalMetadata = 0; keyValuePair_t *keyPairForm_additionalMetadata = 0; if (additionalMetadata != NULL) { @@ -666,7 +675,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata // form parameters char *keyForm_file = NULL; - binary_t* valueForm_file; + binary_t* valueForm_file = 0; keyValuePair_t *keyPairForm_file = 0; if (file != NULL) { @@ -715,7 +724,10 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId , char * additionalMetadata free(keyForm_additionalMetadata); keyForm_additionalMetadata = NULL; } - free(valueForm_additionalMetadata); + if (valueForm_additionalMetadata) { + free(valueForm_additionalMetadata); + valueForm_additionalMetadata = NULL; + } free(keyPairForm_additionalMetadata); if (keyForm_file) { free(keyForm_file);