kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

Memory Leak in V2beta2Autoscaling #132

Closed minerba closed 1 year ago

minerba commented 1 year ago

Hi @ityuhui

I found some Leak Case in AutoscalingV2beta2.

Last time I request this Issue. I know this is rare case that Namespace is Null.

But If Namespace is Null, It Occur some problem in System.

`v2beta2_horizontal_pod_autoscaler_list_t AutoscalingV2beta2API_listNamespacedHorizontalPodAutoscaler(apiClient_t apiClient, char _namespace , char pretty , int allowWatchBookmarks , char _continue , char fieldSelector , char labelSelector , int limit , char resourceVersion , int timeoutSeconds , int watch ) { list_t localVarQueryParameters = list_create(); list_t localVarHeaderParameters = NULL; list_t localVarFormParameters = NULL; list_t localVarHeaderType = list_create(); list_t localVarContentType = NULL; char localVarBodyParameters = NULL;

// create the path
long sizeOfPath = strlen("/apis/autoscaling/v2beta2/namespaces/{namespace}/horizontalpodautoscalers")+1;
char *localVarPath = malloc(sizeOfPath);
snprintf(localVarPath, sizeOfPath, "/apis/autoscaling/v2beta2/namespaces/{namespace}/horizontalpodautoscalers");

// Path Params
long sizeOfPathParams_namespace = strlen(_namespace)+3 + strlen("{ namespace }");
if(_namespace == NULL) {
    goto end;
}`

I think It need to Fix in OpenApiGenerator. Can you fix it?

ityuhui commented 1 year ago

Do you mean the memory leak of localVarPath if _namespace == NULL ?

minerba commented 1 year ago

@ityuhui yes. If the case does not occur at all, it would be better to remove the case "if(_namespace==NULL)".

ityuhui commented 1 year ago

The parameter _namespace is required for the "Namespaced" functions such as AutoscalingV2beta2API_listNamespacedHorizontalPodAutoscaler, so if(_namespace==NULL) needs to be checked.

This issue is a memory leak, what I try to fix is to free the memory when _namespace==NULL.

ityuhui commented 1 year ago

Checked the code and found localVarPath would be freed.

https://github.com/kubernetes-client/c/blob/8f8874e9f5f1023735cc630efb2d354556c0b179/kubernetes/api/AutoscalingV2beta1API.c#L1522-L1524

Is there a memroy leak now ?

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale