kubernetes-client / c

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

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

Closed hariramshankar closed 1 year ago

hariramshankar commented 1 year ago

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; <<<<<
    }
ityuhui commented 1 year ago

Thank you for reporting this issue.

Will fix it later.

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

ityuhui commented 1 year ago

/remove-lifecycle stale

joyantamishu commented 1 year ago

Any update on this? I experienced the same.

ityuhui commented 1 year ago

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