1
1

fix: Fix memory management issues around calls to cJSON_Print() (#997)

Related to #883.
Этот коммит содержится в:
Bruce A. Mah 2020-05-19 07:44:09 -07:00 коммит произвёл GitHub
родитель de848cffad
Коммит 79630e8734
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23

Просмотреть файл

@ -1768,7 +1768,9 @@ send_parameters(struct iperf_test *test)
cJSON_AddStringToObject(j, "client_version", IPERF_VERSION);
if (test->debug) {
printf("send_parameters:\n%s\n", cJSON_Print(j));
char *str = cJSON_Print(j);
printf("send_parameters:\n%s\n", str);
cJSON_free(str);
}
if (JSON_write(test->ctrl_sck, j) < 0) {
@ -1798,7 +1800,7 @@ get_parameters(struct iperf_test *test)
char *str;
str = cJSON_Print(j);
printf("get_parameters:\n%s\n", str );
free(str);
cJSON_free(str);
}
if ((j_p = cJSON_GetObjectItem(j, "tcp")) != NULL)
@ -1965,7 +1967,7 @@ send_results(struct iperf_test *test)
if (r == 0 && test->debug) {
char *str = cJSON_Print(j);
printf("send_results\n%s\n", str);
free(str);
cJSON_free(str);
}
if (r == 0 && JSON_write(test->ctrl_sck, j) < 0) {
i_errno = IESENDRESULTS;
@ -2023,7 +2025,7 @@ get_results(struct iperf_test *test)
if (test->debug) {
char *str = cJSON_Print(j);
printf("get_results\n%s\n", str);
free(str);
cJSON_free(str);
}
test->remote_cpu_util[0] = j_cpu_util_total->valuedouble;
@ -2160,7 +2162,7 @@ JSON_write(int fd, cJSON *json)
if (Nwrite(fd, str, hsize, Ptcp) < 0)
r = -1;
}
free(str);
cJSON_free(str);
}
return r;
}
@ -3447,7 +3449,9 @@ iperf_print_results(struct iperf_test *test)
/* Print server output if we're on the client and it was requested/provided */
if (test->role == 'c' && iperf_get_test_get_server_output(test) && !test->json_output) {
if (test->json_server_output) {
iperf_printf(test, "\nServer JSON output:\n%s\n", cJSON_Print(test->json_server_output));
char *str = cJSON_Print(test->json_server_output);
iperf_printf(test, "\nServer JSON output:\n%s\n", str);
cJSON_free(str);
cJSON_Delete(test->json_server_output);
test->json_server_output = NULL;
}
@ -4031,6 +4035,8 @@ iperf_json_finish(struct iperf_test *test)
return -1;
fprintf(test->outfile, "%s\n", test->json_output_string);
iflush(test);
cJSON_free(test->json_output_string);
test->json_output_string = NULL;
cJSON_Delete(test->json_top);
test->json_top = test->json_start = test->json_connected = test->json_intervals = test->json_server_output = test->json_end = NULL;
return 0;