c icon indicating copy to clipboard operation
c copied to clipboard

Memory Leak in V2beta2Autoscaling

Open minerba opened this issue 3 years ago • 4 comments

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?

minerba avatar Jul 25 '22 08:07 minerba

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

ityuhui avatar Jul 25 '22 13:07 ityuhui

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

minerba avatar Jul 26 '22 08:07 minerba

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 avatar Jul 28 '22 01:07 ityuhui

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 ?

ityuhui avatar Jul 29 '22 08:07 ityuhui

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:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

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

/lifecycle stale

k8s-triage-robot avatar Oct 27 '22 08:10 k8s-triage-robot