Fix Potential Handler Leaks #1

Add pclose before function out
This commit is contained in:
903d09f6-e821-4655-9e8b-7e6068b26f74
2024-07-23 10:17:48 +09:00
committed by GitHub
parent 35d313f4ab
commit fd735fca4b

View File

@@ -75,6 +75,11 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
result_string = calloc(1, KUBECONFIG_EXEC_RESULT_BUFFER_SIZE); result_string = calloc(1, KUBECONFIG_EXEC_RESULT_BUFFER_SIZE);
if (!result_string) { if (!result_string) {
fprintf(stderr, "%s: Cannot allocate memory for command result.[%s]\n", fname, strerror(errno)); fprintf(stderr, "%s: Cannot allocate memory for command result.[%s]\n", fname, strerror(errno));
#ifndef _WIN32
pclose(fp);
#else
_pclose(fp);
#endif
return -1; return -1;
} }
int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1; int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1;
@@ -85,6 +90,11 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
if (result_string_remaining_size <= 0) { if (result_string_remaining_size <= 0) {
fprintf(stderr, "%s: The buffer for exec result is not sufficient.\n", fname); fprintf(stderr, "%s: The buffer for exec result is not sufficient.\n", fname);
rc = -1; rc = -1;
#ifndef _WIN32
pclose(fp);
#else
_pclose(fp);
#endif
goto end; goto end;
} }
strncat(result_string, string_buf, strlen(string_buf)); strncat(result_string, string_buf, strlen(string_buf));