From 7c9a154803c0293a8c0b51bbec65dc00a950989e Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 26 Mar 2016 01:33:34 +0100 Subject: Sanitize mallocs and frees. --- test/core/network_benchmarks/low_level_ping_pong.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'test/core/network_benchmarks') diff --git a/test/core/network_benchmarks/low_level_ping_pong.c b/test/core/network_benchmarks/low_level_ping_pong.c index 7ed3372d5d..8179ba3b4d 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.c +++ b/test/core/network_benchmarks/low_level_ping_pong.c @@ -265,19 +265,19 @@ static int epoll_setup(thread_args *args) { #endif static void server_thread(thread_args *args) { - char *buf = malloc(args->msg_size); + char *buf = gpr_malloc(args->msg_size); if (args->setup(args) < 0) { gpr_log(GPR_ERROR, "Setup failed"); } for (;;) { if (args->read_bytes(args, buf) < 0) { gpr_log(GPR_ERROR, "Server read failed"); - free(buf); + gpr_free(buf); return; } if (args->write_bytes(args, buf) < 0) { gpr_log(GPR_ERROR, "Server write failed"); - free(buf); + gpr_free(buf); return; } } @@ -304,7 +304,8 @@ static double now(void) { } static void client_thread(thread_args *args) { - char *buf = calloc(args->msg_size, sizeof(char)); + char *buf = gpr_malloc(args->msg_size * sizeof(char)); + memset(buf, 0, args->msg_size * sizeof(char)); gpr_histogram *histogram = gpr_histogram_create(0.01, 60e9); double start_time; double end_time; @@ -333,7 +334,7 @@ static void client_thread(thread_args *args) { } print_histogram(histogram); error: - free(buf); + gpr_free(buf); gpr_histogram_destroy(histogram); } @@ -596,8 +597,8 @@ static int run_all_benchmarks(size_t msg_size) { test_strategy *strategy = &test_strategies[i]; size_t j; for (j = 0; j < GPR_ARRAY_SIZE(socket_types); ++j) { - thread_args *client_args = malloc(sizeof(thread_args)); - thread_args *server_args = malloc(sizeof(thread_args)); + thread_args *client_args = gpr_malloc(sizeof(thread_args)); + thread_args *server_args = gpr_malloc(sizeof(thread_args)); char *socket_type = socket_types[j]; client_args->read_bytes = strategy->read_strategy; @@ -620,8 +621,8 @@ static int run_all_benchmarks(size_t msg_size) { } int main(int argc, char **argv) { - thread_args *client_args = malloc(sizeof(thread_args)); - thread_args *server_args = malloc(sizeof(thread_args)); + thread_args *client_args = gpr_malloc(sizeof(thread_args)); + thread_args *server_args = gpr_malloc(sizeof(thread_args)); int msg_size = -1; char *read_strategy = NULL; char *socket_type = NULL; -- cgit v1.2.3