aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lib/iomgr/tcp_server_posix.c2
-rw-r--r--src/core/lib/iomgr/tcp_server_windows.c2
-rw-r--r--src/core/lib/iomgr/udp_server.c2
-rw-r--r--src/core/lib/profiling/basic_timers.c4
-rw-r--r--src/core/lib/support/thd_posix.c1
-rw-r--r--src/core/lib/surface/byte_buffer.c6
-rw-r--r--src/core/lib/tsi/fake_transport_security.c19
-rw-r--r--src/core/lib/tsi/ssl_transport_security.c68
-rw-r--r--src/core/lib/tsi/transport_security.c16
9 files changed, 55 insertions, 65 deletions
diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c
index ef1bf9aa94..e9c7f4ef5c 100644
--- a/src/core/lib/iomgr/tcp_server_posix.c
+++ b/src/core/lib/iomgr/tcp_server_posix.c
@@ -451,7 +451,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
&sockname_len)) {
port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
if (port > 0) {
- allocated_addr = malloc(addr_len);
+ allocated_addr = gpr_malloc(addr_len);
memcpy(allocated_addr, addr, addr_len);
grpc_sockaddr_set_port(allocated_addr, port);
addr = allocated_addr;
diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c
index 3d6a29b2e2..3db92aa41a 100644
--- a/src/core/lib/iomgr/tcp_server_windows.c
+++ b/src/core/lib/iomgr/tcp_server_windows.c
@@ -467,7 +467,7 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
(struct sockaddr *)&sockname_temp, &sockname_len)) {
port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
if (port > 0) {
- allocated_addr = malloc(addr_len);
+ allocated_addr = gpr_malloc(addr_len);
memcpy(allocated_addr, addr, addr_len);
grpc_sockaddr_set_port(allocated_addr, port);
addr = allocated_addr;
diff --git a/src/core/lib/iomgr/udp_server.c b/src/core/lib/iomgr/udp_server.c
index 3d8bcc9c81..06f5d3dc8b 100644
--- a/src/core/lib/iomgr/udp_server.c
+++ b/src/core/lib/iomgr/udp_server.c
@@ -337,7 +337,7 @@ int grpc_udp_server_add_port(grpc_udp_server *s, const void *addr,
&sockname_len)) {
port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
if (port > 0) {
- allocated_addr = malloc(addr_len);
+ allocated_addr = gpr_malloc(addr_len);
memcpy(allocated_addr, addr, addr_len);
grpc_sockaddr_set_port(allocated_addr, port);
addr = allocated_addr;
diff --git a/src/core/lib/profiling/basic_timers.c b/src/core/lib/profiling/basic_timers.c
index 15a9584981..2b17cb2dc8 100644
--- a/src/core/lib/profiling/basic_timers.c
+++ b/src/core/lib/profiling/basic_timers.c
@@ -173,7 +173,7 @@ static void flush_logs(gpr_timer_log_list *list) {
gpr_timer_log *log;
while ((log = timer_log_pop_front(list)) != NULL) {
write_log(log);
- free(log);
+ gpr_free(log);
}
}
@@ -208,7 +208,7 @@ static void init_output() {
}
static void rotate_log() {
- gpr_timer_log *new = malloc(sizeof(*new));
+ gpr_timer_log *new = gpr_malloc(sizeof(*new));
gpr_once_init(&g_once_init, init_output);
new->num_entries = 0;
pthread_mutex_lock(&g_mu);
diff --git a/src/core/lib/support/thd_posix.c b/src/core/lib/support/thd_posix.c
index 4d874d3656..1c703844b4 100644
--- a/src/core/lib/support/thd_posix.c
+++ b/src/core/lib/support/thd_posix.c
@@ -81,6 +81,7 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg,
thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0);
GPR_ASSERT(pthread_attr_destroy(&attr) == 0);
if (!thread_started) {
+ /* don't use gpr_free, as this was allocated using malloc (see above) */
free(a);
}
*t = (gpr_thd_id)p;
diff --git a/src/core/lib/surface/byte_buffer.c b/src/core/lib/surface/byte_buffer.c
index 03071ef92c..314a67dfcc 100644
--- a/src/core/lib/surface/byte_buffer.c
+++ b/src/core/lib/surface/byte_buffer.c
@@ -44,7 +44,7 @@ grpc_byte_buffer *grpc_raw_byte_buffer_create(gpr_slice *slices,
grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create(
gpr_slice *slices, size_t nslices, grpc_compression_algorithm compression) {
size_t i;
- grpc_byte_buffer *bb = malloc(sizeof(grpc_byte_buffer));
+ grpc_byte_buffer *bb = gpr_malloc(sizeof(grpc_byte_buffer));
bb->type = GRPC_BB_RAW;
bb->data.raw.compression = compression;
gpr_slice_buffer_init(&bb->data.raw.slice_buffer);
@@ -57,7 +57,7 @@ grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create(
grpc_byte_buffer *grpc_raw_byte_buffer_from_reader(
grpc_byte_buffer_reader *reader) {
- grpc_byte_buffer *bb = malloc(sizeof(grpc_byte_buffer));
+ grpc_byte_buffer *bb = gpr_malloc(sizeof(grpc_byte_buffer));
gpr_slice slice;
bb->type = GRPC_BB_RAW;
bb->data.raw.compression = GRPC_COMPRESS_NONE;
@@ -85,7 +85,7 @@ void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) {
gpr_slice_buffer_destroy(&bb->data.raw.slice_buffer);
break;
}
- free(bb);
+ gpr_free(bb);
}
size_t grpc_byte_buffer_length(grpc_byte_buffer *bb) {
diff --git a/src/core/lib/tsi/fake_transport_security.c b/src/core/lib/tsi/fake_transport_security.c
index 4b812f4803..350cd9b648 100644
--- a/src/core/lib/tsi/fake_transport_security.c
+++ b/src/core/lib/tsi/fake_transport_security.c
@@ -134,12 +134,12 @@ static void tsi_fake_frame_reset(tsi_fake_frame *frame, int needs_draining) {
static int tsi_fake_frame_ensure_size(tsi_fake_frame *frame) {
if (frame->data == NULL) {
frame->allocated_size = frame->size;
- frame->data = malloc(frame->allocated_size);
+ frame->data = gpr_malloc(frame->allocated_size);
if (frame->data == NULL) return 0;
} else if (frame->size > frame->allocated_size) {
unsigned char *new_data = realloc(frame->data, frame->size);
if (new_data == NULL) {
- free(frame->data);
+ gpr_free(frame->data);
frame->data = NULL;
return 0;
}
@@ -160,7 +160,7 @@ static tsi_result fill_frame_from_bytes(const unsigned char *incoming_bytes,
if (frame->needs_draining) return TSI_INTERNAL_ERROR;
if (frame->data == NULL) {
frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE;
- frame->data = malloc(frame->allocated_size);
+ frame->data = gpr_malloc(frame->allocated_size);
if (frame->data == NULL) return TSI_OUT_OF_RESOURCES;
}
@@ -226,7 +226,7 @@ static tsi_result bytes_to_frame(unsigned char *bytes, size_t bytes_size,
}
static void tsi_fake_frame_destruct(tsi_fake_frame *frame) {
- if (frame->data != NULL) free(frame->data);
+ if (frame->data != NULL) gpr_free(frame->data);
}
/* --- tsi_frame_protector methods implementation. ---*/
@@ -366,7 +366,7 @@ static void fake_protector_destroy(tsi_frame_protector *self) {
tsi_fake_frame_protector *impl = (tsi_fake_frame_protector *)self;
tsi_fake_frame_destruct(&impl->protect_frame);
tsi_fake_frame_destruct(&impl->unprotect_frame);
- free(self);
+ gpr_free(self);
}
static const tsi_frame_protector_vtable frame_protector_vtable = {
@@ -488,7 +488,7 @@ static void fake_handshaker_destroy(tsi_handshaker *self) {
tsi_fake_handshaker *impl = (tsi_fake_handshaker *)self;
tsi_fake_frame_destruct(&impl->incoming);
tsi_fake_frame_destruct(&impl->outgoing);
- free(self);
+ gpr_free(self);
}
static const tsi_handshaker_vtable handshaker_vtable = {
@@ -501,7 +501,8 @@ static const tsi_handshaker_vtable handshaker_vtable = {
};
tsi_handshaker *tsi_create_fake_handshaker(int is_client) {
- tsi_fake_handshaker *impl = calloc(1, sizeof(tsi_fake_handshaker));
+ tsi_fake_handshaker *impl = gpr_malloc(sizeof(*impl));
+ memset(impl, 0, sizeof(*impl));
impl->base.vtable = &handshaker_vtable;
impl->is_client = is_client;
impl->result = TSI_HANDSHAKE_IN_PROGRESS;
@@ -517,8 +518,8 @@ tsi_handshaker *tsi_create_fake_handshaker(int is_client) {
tsi_frame_protector *tsi_create_fake_protector(
size_t *max_protected_frame_size) {
- tsi_fake_frame_protector *impl = calloc(1, sizeof(tsi_fake_frame_protector));
- if (impl == NULL) return NULL;
+ tsi_fake_frame_protector *impl = gpr_malloc(sizeof(*impl));
+ memset(impl, 0, sizeof(*impl));
impl->max_frame_size = (max_protected_frame_size == NULL)
? TSI_FAKE_DEFAULT_FRAME_SIZE
: *max_protected_frame_size;
diff --git a/src/core/lib/tsi/ssl_transport_security.c b/src/core/lib/tsi/ssl_transport_security.c
index d03201eec6..542f870d06 100644
--- a/src/core/lib/tsi/ssl_transport_security.c
+++ b/src/core/lib/tsi/ssl_transport_security.c
@@ -148,8 +148,7 @@ static void init_openssl(void) {
OpenSSL_add_all_algorithms();
num_locks = CRYPTO_num_locks();
GPR_ASSERT(num_locks > 0);
- openssl_mutexes = malloc((size_t)num_locks * sizeof(gpr_mu));
- GPR_ASSERT(openssl_mutexes != NULL);
+ openssl_mutexes = gpr_malloc((size_t)num_locks * sizeof(gpr_mu));
for (i = 0; i < CRYPTO_num_locks(); i++) {
gpr_mu_init(&openssl_mutexes[i]);
}
@@ -701,7 +700,7 @@ static tsi_result build_alpn_protocol_name_list(
}
*protocol_name_list_length += (size_t)alpn_protocols_lengths[i] + 1;
}
- *protocol_name_list = malloc(*protocol_name_list_length);
+ *protocol_name_list = gpr_malloc(*protocol_name_list_length);
if (*protocol_name_list == NULL) return TSI_OUT_OF_RESOURCES;
current = *protocol_name_list;
for (i = 0; i < num_alpn_protocols; i++) {
@@ -852,9 +851,9 @@ static tsi_result ssl_protector_unprotect(
static void ssl_protector_destroy(tsi_frame_protector *self) {
tsi_ssl_frame_protector *impl = (tsi_ssl_frame_protector *)self;
- if (impl->buffer != NULL) free(impl->buffer);
+ if (impl->buffer != NULL) gpr_free(impl->buffer);
if (impl->ssl != NULL) SSL_free(impl->ssl);
- free(self);
+ gpr_free(self);
}
static const tsi_frame_protector_vtable frame_protector_vtable = {
@@ -966,8 +965,9 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker *self,
if (alpn_selected != NULL) {
size_t i;
tsi_peer_property *new_properties =
- calloc(1, sizeof(tsi_peer_property) * (peer->property_count + 1));
- if (new_properties == NULL) return TSI_OUT_OF_RESOURCES;
+ gpr_malloc(sizeof(*new_properties) * (peer->property_count + 1));
+ memset(new_properties, 0,
+ sizeof(*new_properties) * (peer->property_count + 1));
for (i = 0; i < peer->property_count; i++) {
new_properties[i] = peer->properties[i];
}
@@ -975,10 +975,10 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker *self,
TSI_SSL_ALPN_SELECTED_PROTOCOL, (const char *)alpn_selected,
alpn_selected_len, &new_properties[peer->property_count]);
if (result != TSI_OK) {
- free(new_properties);
+ gpr_free(new_properties);
return result;
}
- if (peer->properties != NULL) free(peer->properties);
+ if (peer->properties != NULL) gpr_free(peer->properties);
peer->property_count++;
peer->properties = new_properties;
}
@@ -991,11 +991,8 @@ static tsi_result ssl_handshaker_create_frame_protector(
size_t actual_max_output_protected_frame_size =
TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND;
tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self;
- tsi_ssl_frame_protector *protector_impl =
- calloc(1, sizeof(tsi_ssl_frame_protector));
- if (protector_impl == NULL) {
- return TSI_OUT_OF_RESOURCES;
- }
+ tsi_ssl_frame_protector *protector_impl = gpr_malloc(sizeof(*protector_impl));
+ memset(protector_impl, 0, sizeof(*protector_impl));
if (max_output_protected_frame_size != NULL) {
if (*max_output_protected_frame_size >
@@ -1011,11 +1008,11 @@ static tsi_result ssl_handshaker_create_frame_protector(
}
protector_impl->buffer_size =
actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD;
- protector_impl->buffer = malloc(protector_impl->buffer_size);
+ protector_impl->buffer = gpr_malloc(protector_impl->buffer_size);
if (protector_impl->buffer == NULL) {
gpr_log(GPR_ERROR,
"Could not allocated buffer for tsi_ssl_frame_protector.");
- free(protector_impl);
+ gpr_free(protector_impl);
return TSI_INTERNAL_ERROR;
}
@@ -1034,7 +1031,7 @@ static tsi_result ssl_handshaker_create_frame_protector(
static void ssl_handshaker_destroy(tsi_handshaker *self) {
tsi_ssl_handshaker *impl = (tsi_ssl_handshaker *)self;
SSL_free(impl->ssl); /* The BIO objects are owned by ssl */
- free(impl);
+ gpr_free(impl);
}
static const tsi_handshaker_vtable handshaker_vtable = {
@@ -1111,11 +1108,8 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX *ctx, int is_client,
SSL_set_accept_state(ssl);
}
- impl = calloc(1, sizeof(tsi_ssl_handshaker));
- if (impl == NULL) {
- SSL_free(ssl);
- return TSI_OUT_OF_RESOURCES;
- }
+ impl = gpr_malloc(sizeof(*impl));
+ memset(impl, 0, sizeof(*impl));
impl->ssl = ssl;
impl->into_ssl = into_ssl;
impl->from_ssl = from_ssl;
@@ -1167,8 +1161,8 @@ static void ssl_client_handshaker_factory_destroy(
tsi_ssl_client_handshaker_factory *impl =
(tsi_ssl_client_handshaker_factory *)self;
if (impl->ssl_context != NULL) SSL_CTX_free(impl->ssl_context);
- if (impl->alpn_protocol_list != NULL) free(impl->alpn_protocol_list);
- free(impl);
+ if (impl->alpn_protocol_list != NULL) gpr_free(impl->alpn_protocol_list);
+ gpr_free(impl);
}
static int client_handshaker_factory_npn_callback(SSL *ssl, unsigned char **out,
@@ -1209,12 +1203,12 @@ static void ssl_server_handshaker_factory_destroy(
tsi_peer_destruct(&impl->ssl_context_x509_subject_names[i]);
}
}
- if (impl->ssl_contexts != NULL) free(impl->ssl_contexts);
+ if (impl->ssl_contexts != NULL) gpr_free(impl->ssl_contexts);
if (impl->ssl_context_x509_subject_names != NULL) {
- free(impl->ssl_context_x509_subject_names);
+ gpr_free(impl->ssl_context_x509_subject_names);
}
- if (impl->alpn_protocol_list != NULL) free(impl->alpn_protocol_list);
- free(impl);
+ if (impl->alpn_protocol_list != NULL) gpr_free(impl->alpn_protocol_list);
+ gpr_free(impl);
}
static int does_entry_match_name(const char *entry, size_t entry_length,
@@ -1333,11 +1327,8 @@ tsi_result tsi_create_ssl_client_handshaker_factory(
return TSI_INVALID_ARGUMENT;
}
- impl = calloc(1, sizeof(tsi_ssl_client_handshaker_factory));
- if (impl == NULL) {
- SSL_CTX_free(ssl_context);
- return TSI_OUT_OF_RESOURCES;
- }
+ impl = gpr_malloc(sizeof(*impl));
+ memset(impl, 0, sizeof(*impl));
impl->ssl_context = ssl_context;
do {
@@ -1411,14 +1402,17 @@ tsi_result tsi_create_ssl_server_handshaker_factory(
return TSI_INVALID_ARGUMENT;
}
- impl = calloc(1, sizeof(tsi_ssl_server_handshaker_factory));
- if (impl == NULL) return TSI_OUT_OF_RESOURCES;
+ impl = gpr_malloc(sizeof(*impl));
+ memset(impl, 0, sizeof(*impl));
impl->base.create_handshaker =
ssl_server_handshaker_factory_create_handshaker;
impl->base.destroy = ssl_server_handshaker_factory_destroy;
- impl->ssl_contexts = calloc(key_cert_pair_count, sizeof(SSL_CTX *));
+ impl->ssl_contexts = gpr_malloc(key_cert_pair_count * sizeof(SSL_CTX *));
+ memset(impl->ssl_contexts, 0, key_cert_pair_count * sizeof(SSL_CTX *));
impl->ssl_context_x509_subject_names =
- calloc(key_cert_pair_count, sizeof(tsi_peer));
+ gpr_malloc(key_cert_pair_count * sizeof(tsi_peer));
+ memset(impl->ssl_context_x509_subject_names, 0,
+ key_cert_pair_count * sizeof(tsi_peer));
if (impl->ssl_contexts == NULL ||
impl->ssl_context_x509_subject_names == NULL) {
tsi_ssl_handshaker_factory_destroy(&impl->base);
diff --git a/src/core/lib/tsi/transport_security.c b/src/core/lib/tsi/transport_security.c
index a2c0d46196..edbbe0ed97 100644
--- a/src/core/lib/tsi/transport_security.c
+++ b/src/core/lib/tsi/transport_security.c
@@ -239,16 +239,10 @@ void tsi_peer_destruct(tsi_peer *self) {
tsi_result tsi_construct_allocated_string_peer_property(
const char *name, size_t value_length, tsi_peer_property *property) {
*property = tsi_init_peer_property();
- if (name != NULL) {
- property->name = tsi_strdup(name);
- if (property->name == NULL) return TSI_OUT_OF_RESOURCES;
- }
+ if (name != NULL) property->name = gpr_strdup(name);
if (value_length > 0) {
- property->value.data = calloc(1, value_length);
- if (property->value.data == NULL) {
- tsi_peer_property_destruct(property);
- return TSI_OUT_OF_RESOURCES;
- }
+ property->value.data = gpr_malloc(value_length);
+ memset(value.data, 0, value_length);
property->value.length = value_length;
}
return TSI_OK;
@@ -276,8 +270,8 @@ tsi_result tsi_construct_string_peer_property(const char *name,
tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer) {
memset(peer, 0, sizeof(tsi_peer));
if (property_count > 0) {
- peer->properties = calloc(property_count, sizeof(tsi_peer_property));
- if (peer->properties == NULL) return TSI_OUT_OF_RESOURCES;
+ peer->properties = gpr_malloc(property_count * sizeof(tsi_peer_property));
+ memset(peer->properties, 0, property_count * sizeof(tsi_peer_property));
peer->property_count = property_count;
}
return TSI_OK;