Skip to content

Commit 2d93989

Browse files
authored
Merge pull request #244 from 903d09f6-e821-4655-9e8b-7e6068b26f74/fix
Fix Potential Handler Leaks in the c/kubernetes/config/
2 parents 35d313f + b448cd1 commit 2d93989

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

kubernetes/config/exec_provider.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
7575
result_string = calloc(1, KUBECONFIG_EXEC_RESULT_BUFFER_SIZE);
7676
if (!result_string) {
7777
fprintf(stderr, "%s: Cannot allocate memory for command result.[%s]\n", fname, strerror(errno));
78-
return -1;
78+
rc = -1;
79+
goto end;
7980
}
8081
int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1;
8182
char string_buf[KUBECONFIG_STRING_BUFFER_SIZE];
@@ -90,11 +91,6 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
9091
strncat(result_string, string_buf, strlen(string_buf));
9192
memset(string_buf, 0, sizeof(string_buf));
9293
}
93-
#ifndef _WIN32
94-
pclose(fp);
95-
#else
96-
_pclose(fp);
97-
#endif
9894
} else {
9995
fprintf(stderr, "%s: Cannot open pipe to run command.[%s]\n", fname, strerror(errno));
10096
return -1;
@@ -105,7 +101,16 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
105101
end:
106102
if (result_string) {
107103
free(result_string);
104+
result_string = NULL;
108105
}
109106

107+
if (fp) {
108+
#ifndef _WIN32
109+
pclose(fp);
110+
#else
111+
_pclose(fp);
112+
#endif
113+
fp = NULL;
114+
}
110115
return rc;
111116
}

kubernetes/config/kube_config_yaml.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ int kubeyaml_save_kubeconfig(const kubeconfig_t * kubeconfig)
10651065
/* Initialize the emitter object. */
10661066
if (!yaml_emitter_initialize(&emitter)) {
10671067
fprintf(stderr, "%s: Could not initialize the emitter object\n", fname);
1068+
fclose(output);
10681069
return -1;
10691070
}
10701071

0 commit comments

Comments
 (0)