Skip to content

Commit

Permalink
Merge pull request #114 from ityuhui/yh-free-parseFromJSON-0329
Browse files Browse the repository at this point in the history
Free the memory of list or map when json parsing fails
  • Loading branch information
k8s-ci-robot authored Mar 30, 2022
2 parents 6cd4058 + 7b6379e commit d2c5def
Show file tree
Hide file tree
Showing 229 changed files with 5,016 additions and 770 deletions.
15 changes: 13 additions & 2 deletions kubernetes/model/core_v1_event_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ core_v1_event_list_t *core_v1_event_list_parseFromJSON(cJSON *core_v1_event_list

core_v1_event_list_t *core_v1_event_list_local_var = NULL;

// define the local list for core_v1_event_list->items
list_t *itemsList = NULL;

// define the local variable for core_v1_event_list->metadata
v1_list_meta_t *metadata_local_nonprim = NULL;

Expand All @@ -134,9 +137,8 @@ core_v1_event_list_t *core_v1_event_list_parseFromJSON(cJSON *core_v1_event_list
goto end;
}

list_t *itemsList;

cJSON *items_local_nonprimitive;
cJSON *items_local_nonprimitive = NULL;
if(!cJSON_IsArray(items)){
goto end; //nonprimitive container
}
Expand Down Expand Up @@ -178,6 +180,15 @@ core_v1_event_list_t *core_v1_event_list_parseFromJSON(cJSON *core_v1_event_list

return core_v1_event_list_local_var;
end:
if (itemsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, itemsList) {
core_v1_event_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(itemsList);
itemsList = NULL;
}
if (metadata_local_nonprim) {
v1_list_meta_free(metadata_local_nonprim);
metadata_local_nonprim = NULL;
Expand Down
15 changes: 13 additions & 2 deletions kubernetes/model/events_v1_event_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ events_v1_event_list_t *events_v1_event_list_parseFromJSON(cJSON *events_v1_even

events_v1_event_list_t *events_v1_event_list_local_var = NULL;

// define the local list for events_v1_event_list->items
list_t *itemsList = NULL;

// define the local variable for events_v1_event_list->metadata
v1_list_meta_t *metadata_local_nonprim = NULL;

Expand All @@ -134,9 +137,8 @@ events_v1_event_list_t *events_v1_event_list_parseFromJSON(cJSON *events_v1_even
goto end;
}

list_t *itemsList;

cJSON *items_local_nonprimitive;
cJSON *items_local_nonprimitive = NULL;
if(!cJSON_IsArray(items)){
goto end; //nonprimitive container
}
Expand Down Expand Up @@ -178,6 +180,15 @@ events_v1_event_list_t *events_v1_event_list_parseFromJSON(cJSON *events_v1_even

return events_v1_event_list_local_var;
end:
if (itemsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, itemsList) {
events_v1_event_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(itemsList);
itemsList = NULL;
}
if (metadata_local_nonprim) {
v1_list_meta_free(metadata_local_nonprim);
metadata_local_nonprim = NULL;
Expand Down
15 changes: 13 additions & 2 deletions kubernetes/model/v1_aggregation_rule.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ v1_aggregation_rule_t *v1_aggregation_rule_parseFromJSON(cJSON *v1_aggregation_r

v1_aggregation_rule_t *v1_aggregation_rule_local_var = NULL;

// define the local list for v1_aggregation_rule->cluster_role_selectors
list_t *cluster_role_selectorsList = NULL;

// v1_aggregation_rule->cluster_role_selectors
cJSON *cluster_role_selectors = cJSON_GetObjectItemCaseSensitive(v1_aggregation_ruleJSON, "clusterRoleSelectors");
list_t *cluster_role_selectorsList;
if (cluster_role_selectors) {
cJSON *cluster_role_selectors_local_nonprimitive;
cJSON *cluster_role_selectors_local_nonprimitive = NULL;
if(!cJSON_IsArray(cluster_role_selectors)){
goto end; //nonprimitive container
}
Expand All @@ -96,6 +98,15 @@ v1_aggregation_rule_t *v1_aggregation_rule_parseFromJSON(cJSON *v1_aggregation_r

return v1_aggregation_rule_local_var;
end:
if (cluster_role_selectorsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, cluster_role_selectorsList) {
v1_label_selector_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(cluster_role_selectorsList);
cluster_role_selectorsList = NULL;
}
return NULL;

}
30 changes: 26 additions & 4 deletions kubernetes/model/v1_api_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ v1_api_group_t *v1_api_group_parseFromJSON(cJSON *v1_api_groupJSON){
// define the local variable for v1_api_group->preferred_version
v1_group_version_for_discovery_t *preferred_version_local_nonprim = NULL;

// define the local list for v1_api_group->server_address_by_client_cidrs
list_t *server_address_by_client_cidrsList = NULL;

// define the local list for v1_api_group->versions
list_t *versionsList = NULL;

// v1_api_group->api_version
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_api_groupJSON, "apiVersion");
if (api_version) {
Expand Down Expand Up @@ -202,9 +208,8 @@ v1_api_group_t *v1_api_group_parseFromJSON(cJSON *v1_api_groupJSON){

// v1_api_group->server_address_by_client_cidrs
cJSON *server_address_by_client_cidrs = cJSON_GetObjectItemCaseSensitive(v1_api_groupJSON, "serverAddressByClientCIDRs");
list_t *server_address_by_client_cidrsList;
if (server_address_by_client_cidrs) {
cJSON *server_address_by_client_cidrs_local_nonprimitive;
cJSON *server_address_by_client_cidrs_local_nonprimitive = NULL;
if(!cJSON_IsArray(server_address_by_client_cidrs)){
goto end; //nonprimitive container
}
Expand All @@ -228,9 +233,8 @@ v1_api_group_t *v1_api_group_parseFromJSON(cJSON *v1_api_groupJSON){
goto end;
}

list_t *versionsList;

cJSON *versions_local_nonprimitive;
cJSON *versions_local_nonprimitive = NULL;
if(!cJSON_IsArray(versions)){
goto end; //nonprimitive container
}
Expand Down Expand Up @@ -263,6 +267,24 @@ v1_api_group_t *v1_api_group_parseFromJSON(cJSON *v1_api_groupJSON){
v1_group_version_for_discovery_free(preferred_version_local_nonprim);
preferred_version_local_nonprim = NULL;
}
if (server_address_by_client_cidrsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, server_address_by_client_cidrsList) {
v1_server_address_by_client_cidr_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(server_address_by_client_cidrsList);
server_address_by_client_cidrsList = NULL;
}
if (versionsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, versionsList) {
v1_group_version_for_discovery_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(versionsList);
versionsList = NULL;
}
return NULL;

}
15 changes: 13 additions & 2 deletions kubernetes/model/v1_api_group_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ v1_api_group_list_t *v1_api_group_list_parseFromJSON(cJSON *v1_api_group_listJSO

v1_api_group_list_t *v1_api_group_list_local_var = NULL;

// define the local list for v1_api_group_list->groups
list_t *groupsList = NULL;

// v1_api_group_list->api_version
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_api_group_listJSON, "apiVersion");
if (api_version) {
Expand All @@ -112,9 +115,8 @@ v1_api_group_list_t *v1_api_group_list_parseFromJSON(cJSON *v1_api_group_listJSO
goto end;
}

list_t *groupsList;

cJSON *groups_local_nonprimitive;
cJSON *groups_local_nonprimitive = NULL;
if(!cJSON_IsArray(groups)){
goto end; //nonprimitive container
}
Expand Down Expand Up @@ -149,6 +151,15 @@ v1_api_group_list_t *v1_api_group_list_parseFromJSON(cJSON *v1_api_group_listJSO

return v1_api_group_list_local_var;
end:
if (groupsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, groupsList) {
v1_api_group_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(groupsList);
groupsList = NULL;
}
return NULL;

}
45 changes: 39 additions & 6 deletions kubernetes/model/v1_api_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,19 @@ v1_api_resource_t *v1_api_resource_parseFromJSON(cJSON *v1_api_resourceJSON){

v1_api_resource_t *v1_api_resource_local_var = NULL;

// define the local list for v1_api_resource->categories
list_t *categoriesList = NULL;

// define the local list for v1_api_resource->short_names
list_t *short_namesList = NULL;

// define the local list for v1_api_resource->verbs
list_t *verbsList = NULL;

// v1_api_resource->categories
cJSON *categories = cJSON_GetObjectItemCaseSensitive(v1_api_resourceJSON, "categories");
list_t *categoriesList;
if (categories) {
cJSON *categories_local;
cJSON *categories_local = NULL;
if(!cJSON_IsArray(categories)) {
goto end;//primitive container
}
Expand Down Expand Up @@ -287,9 +295,8 @@ v1_api_resource_t *v1_api_resource_parseFromJSON(cJSON *v1_api_resourceJSON){

// v1_api_resource->short_names
cJSON *short_names = cJSON_GetObjectItemCaseSensitive(v1_api_resourceJSON, "shortNames");
list_t *short_namesList;
if (short_names) {
cJSON *short_names_local;
cJSON *short_names_local = NULL;
if(!cJSON_IsArray(short_names)) {
goto end;//primitive container
}
Expand Down Expand Up @@ -332,9 +339,8 @@ v1_api_resource_t *v1_api_resource_parseFromJSON(cJSON *v1_api_resourceJSON){
goto end;
}

list_t *verbsList;

cJSON *verbs_local;
cJSON *verbs_local = NULL;
if(!cJSON_IsArray(verbs)) {
goto end;//primitive container
}
Expand Down Expand Up @@ -374,6 +380,33 @@ v1_api_resource_t *v1_api_resource_parseFromJSON(cJSON *v1_api_resourceJSON){

return v1_api_resource_local_var;
end:
if (categoriesList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, categoriesList) {
free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(categoriesList);
categoriesList = NULL;
}
if (short_namesList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, short_namesList) {
free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(short_namesList);
short_namesList = NULL;
}
if (verbsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, verbsList) {
free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(verbsList);
verbsList = NULL;
}
return NULL;

}
15 changes: 13 additions & 2 deletions kubernetes/model/v1_api_resource_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ v1_api_resource_list_t *v1_api_resource_list_parseFromJSON(cJSON *v1_api_resourc

v1_api_resource_list_t *v1_api_resource_list_local_var = NULL;

// define the local list for v1_api_resource_list->resources
list_t *resourcesList = NULL;

// v1_api_resource_list->api_version
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_api_resource_listJSON, "apiVersion");
if (api_version) {
Expand Down Expand Up @@ -149,9 +152,8 @@ v1_api_resource_list_t *v1_api_resource_list_parseFromJSON(cJSON *v1_api_resourc
goto end;
}

list_t *resourcesList;

cJSON *resources_local_nonprimitive;
cJSON *resources_local_nonprimitive = NULL;
if(!cJSON_IsArray(resources)){
goto end; //nonprimitive container
}
Expand All @@ -178,6 +180,15 @@ v1_api_resource_list_t *v1_api_resource_list_parseFromJSON(cJSON *v1_api_resourc

return v1_api_resource_list_local_var;
end:
if (resourcesList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, resourcesList) {
v1_api_resource_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(resourcesList);
resourcesList = NULL;
}
return NULL;

}
15 changes: 13 additions & 2 deletions kubernetes/model/v1_api_service_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ v1_api_service_list_t *v1_api_service_list_parseFromJSON(cJSON *v1_api_service_l

v1_api_service_list_t *v1_api_service_list_local_var = NULL;

// define the local list for v1_api_service_list->items
list_t *itemsList = NULL;

// define the local variable for v1_api_service_list->metadata
v1_list_meta_t *metadata_local_nonprim = NULL;

Expand All @@ -134,9 +137,8 @@ v1_api_service_list_t *v1_api_service_list_parseFromJSON(cJSON *v1_api_service_l
goto end;
}

list_t *itemsList;

cJSON *items_local_nonprimitive;
cJSON *items_local_nonprimitive = NULL;
if(!cJSON_IsArray(items)){
goto end; //nonprimitive container
}
Expand Down Expand Up @@ -178,6 +180,15 @@ v1_api_service_list_t *v1_api_service_list_parseFromJSON(cJSON *v1_api_service_l

return v1_api_service_list_local_var;
end:
if (itemsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, itemsList) {
v1_api_service_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(itemsList);
itemsList = NULL;
}
if (metadata_local_nonprim) {
v1_list_meta_free(metadata_local_nonprim);
metadata_local_nonprim = NULL;
Expand Down
15 changes: 13 additions & 2 deletions kubernetes/model/v1_api_service_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ v1_api_service_status_t *v1_api_service_status_parseFromJSON(cJSON *v1_api_servi

v1_api_service_status_t *v1_api_service_status_local_var = NULL;

// define the local list for v1_api_service_status->conditions
list_t *conditionsList = NULL;

// v1_api_service_status->conditions
cJSON *conditions = cJSON_GetObjectItemCaseSensitive(v1_api_service_statusJSON, "conditions");
list_t *conditionsList;
if (conditions) {
cJSON *conditions_local_nonprimitive;
cJSON *conditions_local_nonprimitive = NULL;
if(!cJSON_IsArray(conditions)){
goto end; //nonprimitive container
}
Expand All @@ -96,6 +98,15 @@ v1_api_service_status_t *v1_api_service_status_parseFromJSON(cJSON *v1_api_servi

return v1_api_service_status_local_var;
end:
if (conditionsList) {
listEntry_t *listEntry = NULL;
list_ForEach(listEntry, conditionsList) {
v1_api_service_condition_free(listEntry->data);
listEntry->data = NULL;
}
list_freeList(conditionsList);
conditionsList = NULL;
}
return NULL;

}
Loading

0 comments on commit d2c5def

Please sign in to comment.