diff options
author | Bruce A. Mah <bmah@es.net> | 2020-08-03 17:49:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-03 17:49:27 -0700 |
commit | 80b7c7b271158407887b3bb280a3583e1cf6bf64 (patch) | |
tree | b461c009ad576609e45722eec0b82b307ab31c3e | |
parent | eeaecf3534ada549182a72a6576dcc8cbea1ef77 (diff) | |
download | iperf3-80b7c7b271158407887b3bb280a3583e1cf6bf64.tar.gz |
fix: Plug various minor memory leaks (#1033)
* fix: Fix memory leaks related to --logfile.
* fix: Fix memory leaks related to loading RSA keys.
* fix: Fix some memory leaks in failure cases in the iperf3 client.
Fixes #1023.
-rw-r--r-- | src/iperf_api.c | 9 | ||||
-rw-r--r-- | src/iperf_auth.c | 2 | ||||
-rw-r--r-- | src/iperf_client_api.c | 28 |
3 files changed, 29 insertions, 10 deletions
diff --git a/src/iperf_api.c b/src/iperf_api.c index ad2453b..88fed30 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -2662,6 +2662,15 @@ iperf_free_test(struct iperf_test *test) free(prot); } + if (test->logfile) { + free(test->logfile); + test->logfile = NULL; + if (test->outfile) { + fclose(test->outfile); + test->outfile = NULL; + } + } + if (test->server_output_text) { free(test->server_output_text); test->server_output_text = NULL; diff --git a/src/iperf_auth.c b/src/iperf_auth.c index b4f2821..eb4610f 100644 --- a/src/iperf_auth.c +++ b/src/iperf_auth.c @@ -174,6 +174,7 @@ EVP_PKEY *load_pubkey_from_base64(const char *buffer) { BIO* bio = BIO_new(BIO_s_mem()); BIO_write(bio, key, key_len); + free(key); EVP_PKEY *pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL); BIO_free(bio); return (pkey); @@ -199,6 +200,7 @@ EVP_PKEY *load_privkey_from_base64(const char *buffer) { BIO* bio = BIO_new(BIO_s_mem()); BIO_write(bio, key, key_len); + free(key); EVP_PKEY *pkey = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL); BIO_free(bio); return (pkey); diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 20ea6fd..61f3560 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014-2018, The Regents of the University of + * iperf, Copyright (c) 2014-2020, The Regents of the University of * California, through Lawrence Berkeley National Laboratory (subject * to receipt of any required approvals from the U.S. Dept. of * Energy). All rights reserved. @@ -478,7 +478,7 @@ iperf_run_client(struct iperf_test * test) /* Start the client and connect to the server */ if (iperf_connect(test) < 0) - return -1; + goto cleanup_and_fail; /* Begin calculating CPU utilization */ cpu_util(NULL); @@ -492,12 +492,12 @@ iperf_run_client(struct iperf_test * test) result = select(test->max_fd + 1, &read_set, &write_set, NULL, timeout); if (result < 0 && errno != EINTR) { i_errno = IESELECT; - return -1; + goto cleanup_and_fail; } if (result > 0) { if (FD_ISSET(test->ctrl_sck, &read_set)) { if (iperf_handle_message_client(test) < 0) { - return -1; + goto cleanup_and_fail; } FD_CLR(test->ctrl_sck, &read_set); } @@ -521,17 +521,17 @@ iperf_run_client(struct iperf_test * test) if (test->mode == BIDIRECTIONAL) { if (iperf_send(test, &write_set) < 0) - return -1; + goto cleanup_and_fail; if (iperf_recv(test, &read_set) < 0) - return -1; + goto cleanup_and_fail; } else if (test->mode == SENDER) { // Regular mode. Client sends. if (iperf_send(test, &write_set) < 0) - return -1; + goto cleanup_and_fail; } else { // Reverse mode. Client receives. if (iperf_recv(test, &read_set) < 0) - return -1; + goto cleanup_and_fail; } @@ -557,7 +557,7 @@ iperf_run_client(struct iperf_test * test) cpu_util(test->cpu_util); test->stats_callback(test); if (iperf_set_send_state(test, TEST_END) != 0) - return -1; + goto cleanup_and_fail; } } // If we're in reverse mode, continue draining the data @@ -567,7 +567,7 @@ iperf_run_client(struct iperf_test * test) // from the client side. else if (test->mode == RECEIVER && test->state == TEST_END) { if (iperf_recv(test, &read_set) < 0) - return -1; + goto cleanup_and_fail; } } @@ -582,4 +582,12 @@ iperf_run_client(struct iperf_test * test) iflush(test); return 0; + + cleanup_and_fail: + iperf_printf(test, "cleanup_and_fail\n"); + iperf_client_end(test); + if (test->json_output) + iperf_json_finish(test); + iflush(test); + return -1; } |