[C][Client] Check the pointer before deleting operation to avoid core dump label:"Client C" (#5626)

* [C-libcurl] Check the pointer before deleting operation to avoid core dump

* [C-libcurl] Check the pointer before deleting operation, update sample
This commit is contained in:
Hui Yu 2020-03-24 09:53:01 +08:00 committed by GitHub
parent b3b3941d09
commit f7fe93b8d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 4 deletions

View File

@ -88,8 +88,10 @@ void list_iterateThroughListBackward(list_t *list,
}
void list_free(list_t *list) {
list_iterateThroughListForward(list, listEntry_free, NULL);
free(list);
if(list){
list_iterateThroughListForward(list, listEntry_free, NULL);
free(list);
}
}
void list_addElement(list_t *list, void *dataToAddInList) {

View File

@ -205,6 +205,9 @@ char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName
void {{classname}}_free({{classname}}_t *{{classname}}) {
if(NULL == {{classname}}){
return ;
}
listEntry_t *listEntry;
{{#vars}}
{{^isContainer}}

View File

@ -23,6 +23,9 @@ api_response_t *api_response_create(
void api_response_free(api_response_t *api_response) {
if(NULL == api_response){
return ;
}
listEntry_t *listEntry;
free(api_response->type);
free(api_response->message);

View File

@ -21,6 +21,9 @@ category_t *category_create(
void category_free(category_t *category) {
if(NULL == category){
return ;
}
listEntry_t *listEntry;
free(category->name);
free(category);

View File

@ -46,6 +46,9 @@ order_t *order_create(
void order_free(order_t *order) {
if(NULL == order){
return ;
}
listEntry_t *listEntry;
free(order->ship_date);
free(order);

View File

@ -46,6 +46,9 @@ pet_t *pet_create(
void pet_free(pet_t *pet) {
if(NULL == pet){
return ;
}
listEntry_t *listEntry;
category_free(pet->category);
free(pet->name);

View File

@ -21,6 +21,9 @@ tag_t *tag_create(
void tag_free(tag_t *tag) {
if(NULL == tag){
return ;
}
listEntry_t *listEntry;
free(tag->name);
free(tag);

View File

@ -33,6 +33,9 @@ user_t *user_create(
void user_free(user_t *user) {
if(NULL == user){
return ;
}
listEntry_t *listEntry;
free(user->username);
free(user->first_name);

View File

@ -88,8 +88,10 @@ void list_iterateThroughListBackward(list_t *list,
}
void list_free(list_t *list) {
list_iterateThroughListForward(list, listEntry_free, NULL);
free(list);
if(list){
list_iterateThroughListForward(list, listEntry_free, NULL);
free(list);
}
}
void list_addElement(list_t *list, void *dataToAddInList) {