Skip to content

Commit

Permalink
Merge pull request #244 from 903d09f6-e821-4655-9e8b-7e6068b26f74/fix
Browse files Browse the repository at this point in the history
Fix Potential Handler Leaks in the c/kubernetes/config/
  • Loading branch information
k8s-ci-robot authored Jul 23, 2024
2 parents 35d313f + b448cd1 commit 2d93989
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions kubernetes/config/exec_provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
result_string = calloc(1, KUBECONFIG_EXEC_RESULT_BUFFER_SIZE);
if (!result_string) {
fprintf(stderr, "%s: Cannot allocate memory for command result.[%s]\n", fname, strerror(errno));
return -1;
rc = -1;
goto end;
}
int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1;
char string_buf[KUBECONFIG_STRING_BUFFER_SIZE];
Expand All @@ -90,11 +91,6 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
strncat(result_string, string_buf, strlen(string_buf));
memset(string_buf, 0, sizeof(string_buf));
}
#ifndef _WIN32
pclose(fp);
#else
_pclose(fp);
#endif
} else {
fprintf(stderr, "%s: Cannot open pipe to run command.[%s]\n", fname, strerror(errno));
return -1;
Expand All @@ -105,7 +101,16 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
end:
if (result_string) {
free(result_string);
result_string = NULL;
}

if (fp) {
#ifndef _WIN32
pclose(fp);
#else
_pclose(fp);
#endif
fp = NULL;
}
return rc;
}
1 change: 1 addition & 0 deletions kubernetes/config/kube_config_yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,7 @@ int kubeyaml_save_kubeconfig(const kubeconfig_t * kubeconfig)
/* Initialize the emitter object. */
if (!yaml_emitter_initialize(&emitter)) {
fprintf(stderr, "%s: Could not initialize the emitter object\n", fname);
fclose(output);
return -1;
}

Expand Down

0 comments on commit 2d93989

Please sign in to comment.