fix: Fix memory management issues around calls to cJSON_Print() (#997)
Related to #883.
Этот коммит содержится в:
родитель
de848cffad
Коммит
79630e8734
@ -1768,7 +1768,9 @@ send_parameters(struct iperf_test *test)
|
|||||||
cJSON_AddStringToObject(j, "client_version", IPERF_VERSION);
|
cJSON_AddStringToObject(j, "client_version", IPERF_VERSION);
|
||||||
|
|
||||||
if (test->debug) {
|
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) {
|
if (JSON_write(test->ctrl_sck, j) < 0) {
|
||||||
@ -1798,7 +1800,7 @@ get_parameters(struct iperf_test *test)
|
|||||||
char *str;
|
char *str;
|
||||||
str = cJSON_Print(j);
|
str = cJSON_Print(j);
|
||||||
printf("get_parameters:\n%s\n", str );
|
printf("get_parameters:\n%s\n", str );
|
||||||
free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((j_p = cJSON_GetObjectItem(j, "tcp")) != NULL)
|
if ((j_p = cJSON_GetObjectItem(j, "tcp")) != NULL)
|
||||||
@ -1965,7 +1967,7 @@ send_results(struct iperf_test *test)
|
|||||||
if (r == 0 && test->debug) {
|
if (r == 0 && test->debug) {
|
||||||
char *str = cJSON_Print(j);
|
char *str = cJSON_Print(j);
|
||||||
printf("send_results\n%s\n", str);
|
printf("send_results\n%s\n", str);
|
||||||
free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
if (r == 0 && JSON_write(test->ctrl_sck, j) < 0) {
|
if (r == 0 && JSON_write(test->ctrl_sck, j) < 0) {
|
||||||
i_errno = IESENDRESULTS;
|
i_errno = IESENDRESULTS;
|
||||||
@ -2023,7 +2025,7 @@ get_results(struct iperf_test *test)
|
|||||||
if (test->debug) {
|
if (test->debug) {
|
||||||
char *str = cJSON_Print(j);
|
char *str = cJSON_Print(j);
|
||||||
printf("get_results\n%s\n", str);
|
printf("get_results\n%s\n", str);
|
||||||
free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
test->remote_cpu_util[0] = j_cpu_util_total->valuedouble;
|
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)
|
if (Nwrite(fd, str, hsize, Ptcp) < 0)
|
||||||
r = -1;
|
r = -1;
|
||||||
}
|
}
|
||||||
free(str);
|
cJSON_free(str);
|
||||||
}
|
}
|
||||||
return r;
|
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 */
|
/* 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->role == 'c' && iperf_get_test_get_server_output(test) && !test->json_output) {
|
||||||
if (test->json_server_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);
|
cJSON_Delete(test->json_server_output);
|
||||||
test->json_server_output = NULL;
|
test->json_server_output = NULL;
|
||||||
}
|
}
|
||||||
@ -4031,6 +4035,8 @@ iperf_json_finish(struct iperf_test *test)
|
|||||||
return -1;
|
return -1;
|
||||||
fprintf(test->outfile, "%s\n", test->json_output_string);
|
fprintf(test->outfile, "%s\n", test->json_output_string);
|
||||||
iflush(test);
|
iflush(test);
|
||||||
|
cJSON_free(test->json_output_string);
|
||||||
|
test->json_output_string = NULL;
|
||||||
cJSON_Delete(test->json_top);
|
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;
|
test->json_top = test->json_start = test->json_connected = test->json_intervals = test->json_server_output = test->json_end = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user