Merge pull request #244 from 903d09f6-e821-4655-9e8b-7e6068b26f74/fix
Fix Potential Handler Leaks in the c/kubernetes/config/
This commit is contained in:
@@ -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);
|
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));
|
||||||
return -1;
|
rc = -1;
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1;
|
int result_string_remaining_size = KUBECONFIG_EXEC_RESULT_BUFFER_SIZE - 1;
|
||||||
char string_buf[KUBECONFIG_STRING_BUFFER_SIZE];
|
char string_buf[KUBECONFIG_STRING_BUFFER_SIZE];
|
||||||
@@ -90,11 +91,6 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
|
|||||||
strncat(result_string, string_buf, strlen(string_buf));
|
strncat(result_string, string_buf, strlen(string_buf));
|
||||||
memset(string_buf, 0, sizeof(string_buf));
|
memset(string_buf, 0, sizeof(string_buf));
|
||||||
}
|
}
|
||||||
#ifndef _WIN32
|
|
||||||
pclose(fp);
|
|
||||||
#else
|
|
||||||
_pclose(fp);
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%s: Cannot open pipe to run command.[%s]\n", fname, strerror(errno));
|
fprintf(stderr, "%s: Cannot open pipe to run command.[%s]\n", fname, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -105,7 +101,16 @@ int kube_exec_and_get_result(ExecCredential_t * exec_credential, const kubeconfi
|
|||||||
end:
|
end:
|
||||||
if (result_string) {
|
if (result_string) {
|
||||||
free(result_string);
|
free(result_string);
|
||||||
|
result_string = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fp) {
|
||||||
|
#ifndef _WIN32
|
||||||
|
pclose(fp);
|
||||||
|
#else
|
||||||
|
_pclose(fp);
|
||||||
|
#endif
|
||||||
|
fp = NULL;
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1065,6 +1065,7 @@ int kubeyaml_save_kubeconfig(const kubeconfig_t * kubeconfig)
|
|||||||
/* Initialize the emitter object. */
|
/* Initialize the emitter object. */
|
||||||
if (!yaml_emitter_initialize(&emitter)) {
|
if (!yaml_emitter_initialize(&emitter)) {
|
||||||
fprintf(stderr, "%s: Could not initialize the emitter object\n", fname);
|
fprintf(stderr, "%s: Could not initialize the emitter object\n", fname);
|
||||||
|
fclose(output);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user