c icon indicating copy to clipboard operation
c copied to clipboard

Memory Leak in kubeyaml_load_kubeconfig() in kubernetes/config/kube_config_yaml.c

Open hariramshankar opened this issue 2 years ago • 1 comments

Hi,

I found a memory leak when calling kubeyaml_load_kubeconfig()

kubeyaml_load_kubeconfig creates a yaml parser object before attempting to read the kubeconfig file.

If opening the kubeconfig file failed for some reason, the function returns(-1) without freeing up the memory allocated to parser.

snippet of the code in question where the leak occurs

    /* Create the Parser object. */
    yaml_parser_initialize(&parser);

    /* Set a file input. */
    FILE *input = NULL;
    if (kubeconfig->fileName) {
        input = fopen(kubeconfig->fileName, "rb");
        if (!input) {
            fprintf(stderr, "%s: Cannot open the file %s.[%s]\n", fname, kubeconfig->fileName, strerror(errno));
            return -1; <<<<<
        }
    } else {
        fprintf(stderr, "%s: The kubeconf file name needs be set by kubeconfig->fileName .\n", fname);
        return -1; <<<<<
    }

hariramshankar avatar Aug 17 '22 18:08 hariramshankar

Thank you for reporting this issue.

Will fix it later.

ityuhui avatar Aug 18 '22 02:08 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 Nov 16 '22 02:11 k8s-triage-robot

/remove-lifecycle stale

ityuhui avatar Nov 16 '22 02:11 ityuhui

Any update on this? I experienced the same.

joyanta55 avatar Jan 12 '23 20:01 joyanta55

I'll find a cycle to fix it in a few days. Fix PRs from anyone are also welcome.

ityuhui avatar Jan 13 '23 02:01 ityuhui