close filehandle only if we opened one
This commit is contained in:
DanyT
2024-07-02 11:58:32 +03:00
parent 6d3bd66121
commit 8f759fcfb7
2 changed files with 9 additions and 4 deletions

View File

@@ -314,7 +314,7 @@ int load_kube_config_common(char **pBasePath, sslConfig_t ** pSslConfig, list_t
rc = kubeyaml_load_kubeconfig(kubeconfig);
if (0 != rc) {
fprintf(stderr, "%s: Cannot load the kubeconfig %s\n", fname, kubeconfig->fileName);
fprintf(stderr, "%s: Cannot load the kubeconfig %s\n", fname, kubeconfig->fileName?kubeconfig->fileName:kubeconfig->buffer);
rc = -1;
goto end;
}

View File

@@ -438,10 +438,11 @@ int kubeyaml_load_kubeconfig(kubeconfig_t * kubeconfig)
fprintf(stderr, "%s: Cannot open the file %s.[%s]\n", fname, kubeconfig->fileName, strerror(errno));
return -1;
}
}
else if (kubeconfig->buffer) {
// Nothing to do here for now.
}
} else {
else {
fprintf(stderr, "%s: The kubeconf file name needs be set by kubeconfig->fileName .\n", fname);
return -1;
}
@@ -477,12 +478,16 @@ int kubeyaml_load_kubeconfig(kubeconfig_t * kubeconfig)
/* Cleanup */
yaml_parser_delete(&parser);
fclose(input);
if (input) {
fclose(input);
}
return 0;
error:
yaml_parser_delete(&parser);
fclose(input);
if (input) {
fclose(input);
}
return -1;
}