Merge pull request #15879 from hcaseyal/client_auth_allocation

Remove allocation in client auth filter and use call arena instead
pull/15938/head
hcaseyal 7 years ago committed by GitHub
commit f0375f86e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/lib/security/context/security_context.cc
  2. 3
      src/core/lib/security/context/security_context.h
  3. 6
      src/core/lib/security/transport/client_auth_filter.cc

@ -50,7 +50,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call,
ctx = static_cast<grpc_client_security_context*>(
grpc_call_context_get(call, GRPC_CONTEXT_SECURITY));
if (ctx == nullptr) {
ctx = grpc_client_security_context_create();
ctx = grpc_client_security_context_create(grpc_call_get_arena(call));
ctx->creds = grpc_call_credentials_ref(creds);
grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx,
grpc_client_security_context_destroy);
@ -82,9 +82,10 @@ void grpc_auth_context_release(grpc_auth_context* context) {
/* --- grpc_client_security_context --- */
grpc_client_security_context* grpc_client_security_context_create(void) {
grpc_client_security_context* grpc_client_security_context_create(
gpr_arena* arena) {
return static_cast<grpc_client_security_context*>(
gpr_zalloc(sizeof(grpc_client_security_context)));
gpr_arena_alloc(arena, sizeof(grpc_client_security_context)));
}
void grpc_client_security_context_destroy(void* ctx) {
@ -96,7 +97,6 @@ void grpc_client_security_context_destroy(void* ctx) {
if (c->extension.instance != nullptr && c->extension.destroy != nullptr) {
c->extension.destroy(c->extension.instance);
}
gpr_free(ctx);
}
/* --- grpc_server_security_context --- */

@ -91,7 +91,8 @@ typedef struct {
grpc_security_context_extension extension;
} grpc_client_security_context;
grpc_client_security_context* grpc_client_security_context_create(void);
grpc_client_security_context* grpc_client_security_context_create(
gpr_arena* arena);
void grpc_client_security_context_destroy(void* ctx);
/* --- grpc_server_security_context ---

@ -42,6 +42,7 @@
namespace {
/* We can have a per-call credentials. */
struct call_data {
gpr_arena* arena;
grpc_call_stack* owning_call;
grpc_call_combiner* call_combiner;
grpc_call_credentials* creds;
@ -276,10 +277,12 @@ static void auth_start_transport_stream_op_batch(
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
if (!batch->cancel_stream) {
// TODO(hcaseyal): move this to init_call_elem once issue #15927 is
// resolved.
GPR_ASSERT(batch->payload->context != nullptr);
if (batch->payload->context[GRPC_CONTEXT_SECURITY].value == nullptr) {
batch->payload->context[GRPC_CONTEXT_SECURITY].value =
grpc_client_security_context_create();
grpc_client_security_context_create(calld->arena);
batch->payload->context[GRPC_CONTEXT_SECURITY].destroy =
grpc_client_security_context_destroy;
}
@ -335,6 +338,7 @@ static void auth_start_transport_stream_op_batch(
static grpc_error* init_call_elem(grpc_call_element* elem,
const grpc_call_element_args* args) {
call_data* calld = static_cast<call_data*>(elem->call_data);
calld->arena = args->arena;
calld->owning_call = args->call_stack;
calld->call_combiner = args->call_combiner;
calld->host = grpc_empty_slice();

Loading…
Cancel
Save