* Fix memory leak when kubeconfig is invalid

* Add a test for this case
This commit is contained in:
Hui Yu
2023-01-16 15:41:01 +08:00
parent 5911cc0ae4
commit 2887dd5fee
5 changed files with 93 additions and 8 deletions

View File

@@ -425,14 +425,6 @@ int kubeyaml_load_kubeconfig(kubeconfig_t * kubeconfig)
{
static char fname[] = "kubeyaml_load_kubeconfig()";
yaml_parser_t parser;
yaml_document_t document;
int done = 0;
/* Create the Parser object. */
yaml_parser_initialize(&parser);
/* Set a file input. */
FILE *input = NULL;
if (kubeconfig->fileName) {
@@ -446,8 +438,14 @@ int kubeyaml_load_kubeconfig(kubeconfig_t * kubeconfig)
return -1;
}
yaml_parser_t parser;
yaml_document_t document;
/* Create the Parser object. */
yaml_parser_initialize(&parser);
yaml_parser_set_input_file(&parser, input);
int done = 0;
while (!done) {
if (!yaml_parser_load(&parser, &document)) {