Fix memory leak detected by ASAN and clang-format variance.

pull/8377/head
Harvey Tuch 8 years ago
parent 8cdf17a620
commit 27c876ecbe
  1. 16
      test/core/handshake/client_ssl.c
  2. 6
      test/core/handshake/server_ssl.c

@ -34,9 +34,9 @@
#include <arpa/inet.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <grpc/grpc.h>
@ -50,8 +50,8 @@
#include "test/core/util/test_config.h"
#define SSL_CERT_PATH "src/core/lib/tsi/test_creds/server1.pem"
#define SSL_KEY_PATH "src/core/lib/tsi/test_creds/server1.key"
#define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem"
#define SSL_KEY_PATH "src/core/lib/tsi/test_creds/server1.key"
#define SSL_CA_PATH "src/core/lib/tsi/test_creds/ca.pem"
// Arguments for TLS server thread.
typedef struct {
@ -185,7 +185,8 @@ static void server_thread(void *arg) {
// Wait until the client drops its connection.
char buf;
while (SSL_read(ssl, &buf, sizeof(buf)) > 0);
while (SSL_read(ssl, &buf, sizeof(buf)) > 0)
;
SSL_free(ssl);
close(client);
@ -208,7 +209,7 @@ static bool client_ssl_test(char *server_alpn_preferred) {
gpr_thd_options thdopt = gpr_thd_options_default();
gpr_thd_id thdid;
gpr_thd_options_set_joinable(&thdopt);
server_args args = { .port = port, .alpn_preferred = server_alpn_preferred };
server_args args = {.port = port, .alpn_preferred = server_alpn_preferred};
GPR_ASSERT(gpr_thd_new(&thdid, server_thread, &args, &thdopt));
// Load key pair and establish client SSL credentials.
@ -220,7 +221,7 @@ static bool client_ssl_test(char *server_alpn_preferred) {
grpc_load_file(SSL_CERT_PATH, 1, &cert_slice)));
GPR_ASSERT(GRPC_LOG_IF_ERROR("load_file",
grpc_load_file(SSL_KEY_PATH, 1, &key_slice)));
const char *ca_cert = (const char*)GPR_SLICE_START_PTR(ca_slice);
const char *ca_cert = (const char *)GPR_SLICE_START_PTR(ca_slice);
pem_key_cert_pair.private_key = (const char *)GPR_SLICE_START_PTR(key_slice);
pem_key_cert_pair.cert_chain = (const char *)GPR_SLICE_START_PTR(cert_slice);
grpc_channel_credentials *ssl_creds =
@ -236,7 +237,8 @@ static bool client_ssl_test(char *server_alpn_preferred) {
grpc_channel_args grpc_args;
grpc_args.num_args = 1;
grpc_args.args = &ssl_name_override;
grpc_channel *channel = grpc_secure_channel_create(ssl_creds, target, &grpc_args, NULL);
grpc_channel *channel =
grpc_secure_channel_create(ssl_creds, target, &grpc_args, NULL);
GPR_ASSERT(channel);
gpr_free(target);

@ -101,6 +101,7 @@ static void server_thread(void *arg) {
gpr_asprintf(&addr, "127.0.0.1:%d", port);
grpc_server *server = grpc_server_create(NULL, NULL);
GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
free(addr);
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
@ -124,6 +125,7 @@ static void server_thread(void *arg) {
grpc_event ev = grpc_completion_queue_next(cq, cq_deadline, NULL);
GPR_ASSERT(ev.type == GRPC_OP_COMPLETE);
grpc_server_destroy(server);
grpc_completion_queue_destroy(cq);
grpc_server_credentials_release(ssl_creds);
gpr_slice_unref(cert_slice);
@ -225,13 +227,15 @@ static bool server_ssl_test(const char *alpn_list[], unsigned int alpn_list_len,
unsigned int alpn_selected_len;
SSL_get0_alpn_selected(ssl, &alpn_selected, &alpn_selected_len);
if (strlen(alpn_expected) != alpn_selected_len ||
strncmp((const char *)alpn_selected, alpn_expected, alpn_selected_len) != 0) {
strncmp((const char *)alpn_selected, alpn_expected,
alpn_selected_len) != 0) {
gpr_log(GPR_ERROR, "Unexpected ALPN protocol preference");
success = false;
}
}
client_handshake_complete = true;
SSL_free(ssl);
gpr_free(alpn_protos);
SSL_CTX_free(ctx);
EVP_cleanup();

Loading…
Cancel
Save