Zalloc or C++ new for structs (#27739)

pull/27714/head
Esun Kim 4 years ago committed by GitHub
parent a2bd7b8440
commit 3b6056aed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  2. 30
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
  3. 22
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h
  4. 12
      src/core/lib/iomgr/executor/mpmcqueue.cc
  5. 11
      src/core/lib/iomgr/executor/mpmcqueue.h
  6. 3
      src/core/lib/iomgr/tcp_server_custom.cc
  7. 3
      src/core/lib/iomgr/tcp_server_posix.cc
  8. 14
      src/core/lib/security/credentials/jwt/jwt_verifier.cc
  9. 3
      src/core/tsi/alts/frame_protector/alts_frame_protector.cc
  10. 9
      src/core/tsi/alts/frame_protector/frame_handler.cc
  11. 3
      src/core/tsi/alts/handshaker/alts_handshaker_client.cc
  12. 3
      src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc
  13. 9
      src/core/tsi/fake_transport_security.cc
  14. 5
      src/core/tsi/local_transport_security.cc
  15. 4
      src/core/tsi/ssl_transport_security.cc
  16. 4
      test/core/end2end/fixtures/http_proxy_fixture.cc
  17. 15
      test/core/iomgr/mpmcqueue_test.cc
  18. 4
      test/core/iomgr/tcp_server_posix_test.cc
  19. 10
      test/core/tsi/ssl_transport_security_test.cc
  20. 9
      test/core/tsi/transport_security_test_lib.cc
  21. 3
      test/core/util/cmdline.cc
  22. 3
      test/core/util/subprocess_posix.cc

@ -313,7 +313,7 @@ void AresDnsResolver::OnResolved(void* arg, grpc_error_handle error) {
void AresDnsResolver::OnResolvedLocked(grpc_error_handle error) {
GPR_ASSERT(resolving_);
resolving_ = false;
gpr_free(pending_request_);
delete pending_request_;
pending_request_ = nullptr;
if (shutdown_initiated_) {
Unref(DEBUG_LOCATION, "OnResolvedLocked() shutdown");

@ -56,29 +56,6 @@ grpc_core::TraceFlag grpc_trace_cares_address_sorting(false,
grpc_core::TraceFlag grpc_trace_cares_resolver(false, "cares_resolver");
typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;
struct grpc_ares_request {
/** indicates the DNS server to use, if specified */
struct ares_addr_port_node dns_server_addr;
/** following members are set in grpc_resolve_address_ares_impl */
/** closure to call when the request completes */
grpc_closure* on_done;
/** the pointer to receive the resolved addresses */
std::unique_ptr<grpc_core::ServerAddressList>* addresses_out;
/** the pointer to receive the resolved balancer addresses */
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses_out;
/** the pointer to receive the service config in JSON */
char** service_config_json_out;
/** the evernt driver used by this request */
grpc_ares_ev_driver* ev_driver;
/** number of ongoing queries */
size_t pending_queries;
/** the errors explaining query failures, appended to in query callbacks */
grpc_error_handle error;
};
typedef struct fd_node {
/** the owner of this fd node */
grpc_ares_ev_driver* ev_driver;
@ -1059,15 +1036,12 @@ static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addrs,
char** service_config_json, int query_timeout_ms,
std::shared_ptr<grpc_core::WorkSerializer> work_serializer) {
grpc_ares_request* r =
static_cast<grpc_ares_request*>(gpr_zalloc(sizeof(grpc_ares_request)));
grpc_ares_request* r = new grpc_ares_request();
r->ev_driver = nullptr;
r->on_done = on_done;
r->addresses_out = addrs;
r->balancer_addresses_out = balancer_addrs;
r->service_config_json_out = service_config_json;
r->error = GRPC_ERROR_NONE;
r->pending_queries = 0;
GRPC_CARES_TRACE_LOG(
"request:%p c-ares grpc_dns_lookup_ares_locked_impl name=%s, "
"default_port=%s",
@ -1163,7 +1137,7 @@ typedef struct grpc_resolve_address_ares_request {
static void on_dns_lookup_done_locked(grpc_resolve_address_ares_request* r,
grpc_error_handle error) {
gpr_free(r->ares_request);
delete r->ares_request;
grpc_resolved_addresses** resolved_addresses = r->addrs_out;
if (r->addresses == nullptr || r->addresses->empty()) {
*resolved_addresses = nullptr;

@ -42,7 +42,27 @@ extern grpc_core::TraceFlag grpc_trace_cares_resolver;
} \
} while (0)
typedef struct grpc_ares_request grpc_ares_request;
typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;
struct grpc_ares_request {
/** indicates the DNS server to use, if specified */
struct ares_addr_port_node dns_server_addr;
/** following members are set in grpc_resolve_address_ares_impl */
/** closure to call when the request completes */
grpc_closure* on_done = nullptr;
/** the pointer to receive the resolved addresses */
std::unique_ptr<grpc_core::ServerAddressList>* addresses_out;
/** the pointer to receive the resolved balancer addresses */
std::unique_ptr<grpc_core::ServerAddressList>* balancer_addresses_out;
/** the pointer to receive the service config in JSON */
char** service_config_json_out = nullptr;
/** the evernt driver used by this request */
grpc_ares_ev_driver* ev_driver = nullptr;
/** number of ongoing queries */
size_t pending_queries = 0;
/** the errors explaining query failures, appended to in query callbacks */
grpc_error_handle error = GRPC_ERROR_NONE;
};
/* Asynchronously resolve \a name. Use \a default_port if a port isn't
designated in \a name, otherwise use the port in \a name. grpc_ares_init()

@ -67,7 +67,7 @@ inline void* InfLenFIFOQueue::PopFront() {
InfLenFIFOQueue::Node* InfLenFIFOQueue::AllocateNodes(int num) {
num_nodes_ = num_nodes_ + num;
Node* new_chunk = static_cast<Node*>(gpr_zalloc(sizeof(Node) * num));
Node* new_chunk = new Node[num];
new_chunk[0].next = &new_chunk[1];
new_chunk[num - 1].prev = &new_chunk[num - 2];
for (int i = 1; i < num - 1; ++i) {
@ -79,8 +79,7 @@ InfLenFIFOQueue::Node* InfLenFIFOQueue::AllocateNodes(int num) {
InfLenFIFOQueue::InfLenFIFOQueue() {
delete_list_size_ = kDeleteListInitSize;
delete_list_ =
static_cast<Node**>(gpr_zalloc(sizeof(Node*) * delete_list_size_));
delete_list_ = new Node*[delete_list_size_];
Node* new_chunk = AllocateNodes(kQueueInitNumNodes);
delete_list_[delete_list_count_++] = new_chunk;
@ -95,9 +94,9 @@ InfLenFIFOQueue::InfLenFIFOQueue() {
InfLenFIFOQueue::~InfLenFIFOQueue() {
GPR_ASSERT(count_.load(std::memory_order_relaxed) == 0);
for (size_t i = 0; i < delete_list_count_; ++i) {
gpr_free(delete_list_[i]);
delete[] delete_list_[i];
}
gpr_free(delete_list_);
delete[] delete_list_;
}
void InfLenFIFOQueue::Put(void* elem) {
@ -112,8 +111,7 @@ void InfLenFIFOQueue::Put(void* elem) {
// Expands delete list on full.
if (delete_list_count_ == delete_list_size_) {
delete_list_size_ = delete_list_size_ * 2;
delete_list_ = static_cast<Node**>(
gpr_realloc(delete_list_, sizeof(Node*) * delete_list_size_));
delete_list_ = new Node*[delete_list_size_];
}
new_chunk[0].prev = queue_tail_->prev;
new_chunk[curr_count - 1].next = queue_head_;

@ -74,15 +74,10 @@ class InfLenFIFOQueue : public MPMCQueueInterface {
int count() const override { return count_.load(std::memory_order_relaxed); }
struct Node {
Node* next; // Linking
Node* prev;
void* content; // Points to actual element
Node* next = nullptr; // Linking
Node* prev = nullptr;
void* content = nullptr; // Points to actual element
gpr_timespec insert_time; // Time for stats
Node() {
next = prev = nullptr;
content = nullptr;
}
};
// For test purpose only. Returns number of nodes allocated in queue.

@ -28,6 +28,7 @@
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/iomgr_custom.h"
@ -303,7 +304,7 @@ static grpc_error_handle add_socket_to_server(grpc_tcp_server* s,
GPR_ASSERT(port >= 0);
GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
sp = static_cast<grpc_tcp_listener*>(gpr_zalloc(sizeof(grpc_tcp_listener)));
sp = grpc_core::Zalloc<grpc_tcp_listener>();
sp->next = nullptr;
if (s->head == nullptr) {
s->head = sp;

@ -64,8 +64,7 @@ static grpc_error_handle tcp_server_create(
grpc_closure* shutdown_complete, const grpc_channel_args* args,
grpc_slice_allocator_factory* slice_allocator_factory,
grpc_tcp_server** server) {
grpc_tcp_server* s =
static_cast<grpc_tcp_server*>(gpr_zalloc(sizeof(grpc_tcp_server)));
grpc_tcp_server* s = grpc_core::Zalloc<grpc_tcp_server>();
s->so_reuseport = grpc_is_socket_reuse_port_supported();
s->expand_wildcard_addrs = false;
for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) {

@ -134,7 +134,7 @@ static void jose_header_destroy(jose_header* h) {
static jose_header* jose_header_from_json(Json json) {
const char* alg_value;
Json::Object::const_iterator it;
jose_header* h = static_cast<jose_header*>(gpr_zalloc(sizeof(jose_header)));
jose_header* h = grpc_core::Zalloc<jose_header>();
if (json.type() != Json::Type::OBJECT) {
gpr_log(GPR_ERROR, "JSON value is not an object");
goto error;
@ -238,8 +238,7 @@ gpr_timespec grpc_jwt_claims_not_before(const grpc_jwt_claims* claims) {
}
grpc_jwt_claims* grpc_jwt_claims_from_json(Json json) {
grpc_jwt_claims* claims =
static_cast<grpc_jwt_claims*>(gpr_zalloc(sizeof(grpc_jwt_claims)));
grpc_jwt_claims* claims = grpc_core::Zalloc<grpc_jwt_claims>();
claims->json.Init(std::move(json));
claims->iat = gpr_inf_past(GPR_CLOCK_REALTIME);
claims->nbf = gpr_inf_past(GPR_CLOCK_REALTIME);
@ -356,8 +355,7 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
grpc_jwt_verification_done_cb cb) {
grpc_core::ApplicationCallbackExecCtx callback_exec_ctx;
grpc_core::ExecCtx exec_ctx;
verifier_cb_ctx* ctx =
static_cast<verifier_cb_ctx*>(gpr_zalloc(sizeof(verifier_cb_ctx)));
verifier_cb_ctx* ctx = new verifier_cb_ctx();
ctx->verifier = verifier;
ctx->pollent = grpc_polling_entity_create_from_pollset(pollset);
ctx->header = header;
@ -367,7 +365,6 @@ static verifier_cb_ctx* verifier_cb_ctx_create(
ctx->signed_data = grpc_slice_from_copied_buffer(signed_jwt, signed_jwt_len);
ctx->user_data = user_data;
ctx->user_cb = cb;
return ctx;
}
@ -381,7 +378,7 @@ void verifier_cb_ctx_destroy(verifier_cb_ctx* ctx) {
grpc_http_response_destroy(&ctx->responses[i]);
}
/* TODO: see what to do with claims... */
gpr_free(ctx);
delete ctx;
}
/* --- grpc_jwt_verifier object. --- */
@ -890,8 +887,7 @@ error:
grpc_jwt_verifier* grpc_jwt_verifier_create(
const grpc_jwt_verifier_email_domain_key_url_mapping* mappings,
size_t num_mappings) {
grpc_jwt_verifier* v =
static_cast<grpc_jwt_verifier*>(gpr_zalloc(sizeof(grpc_jwt_verifier)));
grpc_jwt_verifier* v = grpc_core::Zalloc<grpc_jwt_verifier>();
grpc_httpcli_context_init(&v->http_ctx);
/* We know at least of one mapping. */

@ -370,8 +370,7 @@ tsi_result alts_create_frame_protector(const uint8_t* key, size_t key_size,
return TSI_INTERNAL_ERROR;
}
char* error_details = nullptr;
alts_frame_protector* impl =
static_cast<alts_frame_protector*>(gpr_zalloc(sizeof(*impl)));
alts_frame_protector* impl = grpc_core::Zalloc<alts_frame_protector>();
grpc_status_code status = create_alts_crypters(
key, key_size, is_client, is_rekey, impl, &error_details);
if (status != GRPC_STATUS_OK) {

@ -29,6 +29,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/memory.h"
/* Use little endian to interpret a string of bytes as uint32_t. */
static uint32_t load_32_le(const unsigned char* buffer) {
return (static_cast<uint32_t>(buffer[3]) << 24) |
@ -47,9 +49,7 @@ static void store_32_le(uint32_t value, unsigned char* buffer) {
/* Frame writer implementation. */
alts_frame_writer* alts_create_frame_writer() {
alts_frame_writer* writer =
static_cast<alts_frame_writer*>(gpr_zalloc(sizeof(*writer)));
return writer;
return grpc_core::Zalloc<alts_frame_writer>();
}
bool alts_reset_frame_writer(alts_frame_writer* writer,
@ -120,8 +120,7 @@ void alts_destroy_frame_writer(alts_frame_writer* writer) { gpr_free(writer); }
/* Frame reader implementation. */
alts_frame_reader* alts_create_frame_reader() {
alts_frame_reader* reader =
static_cast<alts_frame_reader*>(gpr_zalloc(sizeof(*reader)));
alts_frame_reader* reader = grpc_core::Zalloc<alts_frame_reader>();
return reader;
}

@ -178,8 +178,7 @@ static void handle_response_done(alts_grpc_handshaker_client* client,
const unsigned char* bytes_to_send,
size_t bytes_to_send_size,
tsi_handshaker_result* result) {
recv_message_result* p =
static_cast<recv_message_result*>(gpr_zalloc(sizeof(*p)));
recv_message_result* p = grpc_core::Zalloc<recv_message_result>();
p->status = status;
p->bytes_to_send = bytes_to_send;
p->bytes_to_send_size = bytes_to_send_size;

@ -32,6 +32,7 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd_id.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/closure.h"
@ -315,7 +316,7 @@ tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp* resp,
// We don't check if local service account is empty here
// because local identity could be empty in certain situations.
alts_tsi_handshaker_result* sresult =
static_cast<alts_tsi_handshaker_result*>(gpr_zalloc(sizeof(*sresult)));
grpc_core::Zalloc<alts_tsi_handshaker_result>();
sresult->key_data =
static_cast<char*>(gpr_zalloc(kAltsAes128GcmRekeyKeyLength));
memcpy(sresult->key_data, key_data.data, kAltsAes128GcmRekeyKeyLength);

@ -27,6 +27,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/tsi/transport_security_grpc.h"
@ -571,8 +572,7 @@ static tsi_result fake_handshaker_result_create(
handshaker_result == nullptr) {
return TSI_INVALID_ARGUMENT;
}
fake_handshaker_result* result =
static_cast<fake_handshaker_result*>(gpr_zalloc(sizeof(*result)));
fake_handshaker_result* result = grpc_core::Zalloc<fake_handshaker_result>();
result->base.vtable = &handshaker_result_vtable;
if (unused_bytes_size > 0) {
result->unused_bytes =
@ -764,8 +764,7 @@ static const tsi_handshaker_vtable handshaker_vtable = {
};
tsi_handshaker* tsi_create_fake_handshaker(int is_client) {
tsi_fake_handshaker* impl =
static_cast<tsi_fake_handshaker*>(gpr_zalloc(sizeof(*impl)));
tsi_fake_handshaker* impl = grpc_core::Zalloc<tsi_fake_handshaker>();
impl->base.vtable = &handshaker_vtable;
impl->is_client = is_client;
impl->result = TSI_HANDSHAKE_IN_PROGRESS;
@ -786,7 +785,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client) {
tsi_frame_protector* tsi_create_fake_frame_protector(
size_t* max_protected_frame_size) {
tsi_fake_frame_protector* impl =
static_cast<tsi_fake_frame_protector*>(gpr_zalloc(sizeof(*impl)));
grpc_core::Zalloc<tsi_fake_frame_protector>();
impl->max_frame_size = (max_protected_frame_size == nullptr)
? TSI_FAKE_DEFAULT_FRAME_SIZE
: *max_protected_frame_size;

@ -108,7 +108,7 @@ static tsi_result create_handshaker_result(bool is_client,
return TSI_INVALID_ARGUMENT;
}
local_tsi_handshaker_result* result =
static_cast<local_tsi_handshaker_result*>(gpr_zalloc(sizeof(*result)));
grpc_core::Zalloc<local_tsi_handshaker_result>();
result->is_client = is_client;
if (received_bytes_size > 0) {
result->unused_bytes =
@ -170,8 +170,7 @@ tsi_result tsi_local_handshaker_create(bool is_client, tsi_handshaker** self) {
gpr_log(GPR_ERROR, "Invalid arguments to local_tsi_handshaker_create()");
return TSI_INVALID_ARGUMENT;
}
local_tsi_handshaker* handshaker =
static_cast<local_tsi_handshaker*>(gpr_zalloc(sizeof(*handshaker)));
local_tsi_handshaker* handshaker = grpc_core::Zalloc<local_tsi_handshaker>();
handshaker->is_client = is_client;
handshaker->base.vtable = &handshaker_vtable;
*self = &handshaker->base;

@ -1390,7 +1390,7 @@ static tsi_result ssl_handshaker_result_create(
return TSI_INVALID_ARGUMENT;
}
tsi_ssl_handshaker_result* result =
static_cast<tsi_ssl_handshaker_result*>(gpr_zalloc(sizeof(*result)));
grpc_core::Zalloc<tsi_ssl_handshaker_result>();
result->base.vtable = &handshaker_result_vtable;
/* Transfer ownership of ssl and network_io to the handshaker result. */
result->ssl = handshaker->ssl;
@ -1669,7 +1669,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client,
SSL_set_accept_state(ssl);
}
impl = static_cast<tsi_ssl_handshaker*>(gpr_zalloc(sizeof(*impl)));
impl = grpc_core::Zalloc<tsi_ssl_handshaker>();
impl->ssl = ssl;
impl->network_io = network_io;
impl->result = TSI_HANDSHAKE_IN_PROGRESS;

@ -33,6 +33,7 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/closure.h"
@ -556,8 +557,7 @@ static void on_accept(void* arg, grpc_endpoint* endpoint,
gpr_free(acceptor);
grpc_end2end_http_proxy* proxy = static_cast<grpc_end2end_http_proxy*>(arg);
// Instantiate proxy_connection.
proxy_connection* conn =
static_cast<proxy_connection*>(gpr_zalloc(sizeof(*conn)));
proxy_connection* conn = grpc_core::Zalloc<proxy_connection>();
gpr_ref(&proxy->users);
conn->client_endpoint = endpoint;
conn->proxy = proxy;

@ -51,7 +51,7 @@ class ProducerThread {
GPR_ASSERT(items_[i]->done);
delete items_[i];
}
gpr_free(items_);
delete[] items_;
}
void Start() { thd_.Start(); }
@ -59,8 +59,7 @@ class ProducerThread {
private:
void Run() {
items_ =
static_cast<WorkItem**>(gpr_zalloc(num_items_ * sizeof(WorkItem*)));
items_ = new WorkItem*[num_items_];
for (int i = 0; i < num_items_; ++i) {
items_[i] = new WorkItem(start_index_ + i);
queue_->Put(items_[i]);
@ -175,10 +174,8 @@ static void test_many_thread(void) {
const int num_producer_threads = 10;
const int num_consumer_threads = 20;
grpc_core::InfLenFIFOQueue queue;
ProducerThread** producer_threads = static_cast<ProducerThread**>(
gpr_zalloc(num_producer_threads * sizeof(ProducerThread*)));
ConsumerThread** consumer_threads = static_cast<ConsumerThread**>(
gpr_zalloc(num_consumer_threads * sizeof(ConsumerThread*)));
ProducerThread** producer_threads = new ProducerThread*[num_producer_threads];
ConsumerThread** consumer_threads = new ConsumerThread*[num_consumer_threads];
gpr_log(GPR_DEBUG, "Fork ProducerThreads...");
for (int i = 0; i < num_producer_threads; ++i) {
@ -211,11 +208,11 @@ static void test_many_thread(void) {
// Destructor of ProducerThread will do the check of WorkItems
delete producer_threads[i];
}
gpr_free(producer_threads);
delete[] producer_threads;
for (int i = 0; i < num_consumer_threads; ++i) {
delete consumer_threads[i];
}
gpr_free(consumer_threads);
delete[] consumer_threads;
gpr_log(GPR_DEBUG, "Done.");
}

@ -39,6 +39,7 @@
#include <grpc/support/time.h>
#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/iomgr/resolve_address.h"
@ -456,8 +457,7 @@ int main(int argc, char** argv) {
struct ifaddrs* ifa = nullptr;
struct ifaddrs* ifa_it;
// Zalloc dst_addrs to avoid oversized frames.
test_addrs* dst_addrs =
static_cast<test_addrs*>(gpr_zalloc(sizeof(*dst_addrs)));
test_addrs* dst_addrs = grpc_core::Zalloc<test_addrs>();
grpc::testing::TestEnvironment env(argc, argv);
grpc_init();
// wait a few seconds to make sure IPv6 link-local addresses can be bound

@ -27,6 +27,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/security_connector/security_connector.h"
#include "src/core/tsi/transport_security.h"
@ -451,14 +452,12 @@ static char* load_file(const char* dir_path, const char* file_name) {
}
static tsi_test_fixture* ssl_tsi_test_fixture_create() {
ssl_tsi_test_fixture* ssl_fixture =
static_cast<ssl_tsi_test_fixture*>(gpr_zalloc(sizeof(*ssl_fixture)));
ssl_tsi_test_fixture* ssl_fixture = grpc_core::Zalloc<ssl_tsi_test_fixture>();
tsi_test_fixture_init(&ssl_fixture->base);
ssl_fixture->base.test_unused_bytes = true;
ssl_fixture->base.vtable = &vtable;
/* Create ssl_key_cert_lib. */
ssl_key_cert_lib* key_cert_lib =
static_cast<ssl_key_cert_lib*>(gpr_zalloc(sizeof(*key_cert_lib)));
ssl_key_cert_lib* key_cert_lib = grpc_core::Zalloc<ssl_key_cert_lib>();
key_cert_lib->use_bad_server_cert = false;
key_cert_lib->use_bad_client_cert = false;
key_cert_lib->use_root_store = false;
@ -500,8 +499,7 @@ static tsi_test_fixture* ssl_tsi_test_fixture_create() {
GPR_ASSERT(key_cert_lib->root_store != nullptr);
ssl_fixture->key_cert_lib = key_cert_lib;
/* Create ssl_alpn_lib. */
ssl_alpn_lib* alpn_lib =
static_cast<ssl_alpn_lib*>(gpr_zalloc(sizeof(*alpn_lib)));
ssl_alpn_lib* alpn_lib = grpc_core::Zalloc<ssl_alpn_lib>();
alpn_lib->server_alpn_protocols = static_cast<const char**>(
gpr_zalloc(sizeof(char*) * SSL_TSI_TEST_ALPN_NUM));
alpn_lib->client_alpn_protocols = static_cast<const char**>(

@ -26,6 +26,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/security/transport/tsi_error.h"
static void notification_signal(tsi_test_fixture* fixture) {
@ -58,8 +59,7 @@ static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture,
bool is_client) {
GPR_ASSERT(fixture != nullptr);
GPR_ASSERT(fixture->config != nullptr);
handshaker_args* args =
static_cast<handshaker_args*>(gpr_zalloc(sizeof(*args)));
handshaker_args* args = new handshaker_args();
args->fixture = fixture;
args->handshake_buffer_size = fixture->handshake_buffer_size;
args->handshake_buffer =
@ -72,7 +72,7 @@ static handshaker_args* handshaker_args_create(tsi_test_fixture* fixture,
static void handshaker_args_destroy(handshaker_args* args) {
gpr_free(args->handshake_buffer);
GRPC_ERROR_UNREF(args->error);
gpr_free(args);
delete args;
}
static void do_handshaker_next(handshaker_args* args);
@ -583,8 +583,7 @@ void tsi_test_frame_protector_config_destroy(
}
static tsi_test_channel* tsi_test_channel_create() {
tsi_test_channel* channel =
static_cast<tsi_test_channel*>(gpr_zalloc(sizeof(*channel)));
tsi_test_channel* channel = grpc_core::Zalloc<tsi_test_channel>();
channel->client_channel =
static_cast<uint8_t*>(gpr_zalloc(TSI_TEST_DEFAULT_CHANNEL_SIZE));
channel->server_channel =

@ -33,6 +33,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/memory.h"
typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;
@ -63,7 +64,7 @@ struct gpr_cmdline {
static int normal_state(gpr_cmdline* cl, char* str);
gpr_cmdline* gpr_cmdline_create(const char* description) {
gpr_cmdline* cl = static_cast<gpr_cmdline*>(gpr_zalloc(sizeof(gpr_cmdline)));
gpr_cmdline* cl = grpc_core::Zalloc<gpr_cmdline>();
cl->description = description;
cl->state = normal_state;

@ -34,6 +34,7 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/memory.h"
#include "test/core/util/subprocess.h"
struct gpr_subprocess {
@ -61,7 +62,7 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) {
gpr_log(GPR_ERROR, "execv '%s' failed: %s", exec_args[0], strerror(errno));
_exit(1);
} else {
r = static_cast<gpr_subprocess*>(gpr_zalloc(sizeof(gpr_subprocess)));
r = grpc_core::Zalloc<gpr_subprocess>();
r->pid = pid;
return r;
}

Loading…
Cancel
Save