kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
148 stars 49 forks source link

Fix Potential Handler Leaks in the c/kubernetes/config/ #244

Closed 903d09f6-e821-4655-9e8b-7e6068b26f74 closed 4 months ago

903d09f6-e821-4655-9e8b-7e6068b26f74 commented 4 months ago

This fix is for issue #243

  1. Add pclose to config/exec_provider.c before kube_exec_and_get_result is returned by the exception handling.
  2. Add fclose to config/kube_config_yaml.c before kubeyaml_save_kubeconfig is returned by the exception handling.
linux-foundation-easycla[bot] commented 4 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

k8s-ci-robot commented 4 months ago

Welcome @903d09f6-e821-4655-9e8b-7e6068b26f74!

It looks like this is your first PR to kubernetes-client/c 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/c has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. :smiley:

ityuhui commented 4 months ago

To avoid duplication, I recommend moving all 3 blocks below

#ifndef _WIN32
            pclose(fp);
#else
            _pclose(fp);
#endif

to the last of function:

  end:
    if (result_string) {
        free(result_string);
        result_string = NULL;    // <-- This time I added a new line
    }

    if (fp) {
#ifndef _WIN32
        pclose(fp);
#else
        _pclose(fp);
#endif
        fp = NULL;   // <-- This time I added a new line
    }

    return rc;

And change https://github.com/kubernetes-client/c/blob/02a71845ae56ebb9910fd578f814fae9a68b435a/kubernetes/config/exec_provider.c#L83

to

rc = -1;
goto end;
903d09f6-e821-4655-9e8b-7e6068b26f74 commented 4 months ago

I agree to your suggestion. HERE is the revision. Thank you.

ityuhui commented 4 months ago

I'm OK with this PR. Please wait a moment to see if @brendandburns has a comment.

brendandburns commented 4 months ago

/lgtm /approve

thanks for the PR!

k8s-ci-robot commented 4 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 903d09f6-e821-4655-9e8b-7e6068b26f74, brendandburns

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-client/c/blob/master/OWNERS)~~ [brendandburns] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment