aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar hcaseyal <hcaseyal@gmail.com>2018-07-03 16:11:49 -0700
committerGravatar GitHub <noreply@github.com>2018-07-03 16:11:49 -0700
commitf0375f86e94f9970283e80996e1326b4416ed4da (patch)
tree95b9d1c28a933f65922808dc9ccfc34c35cf5174 /src
parent024c6633124f689912a9b80da13e89b811ac3e85 (diff)
parent71566ffa932b6941c700ffbd624eb64014639b30 (diff)
Merge pull request #15879 from hcaseyal/client_auth_allocation
Remove allocation in client auth filter and use call arena instead
Diffstat (limited to 'src')
-rw-r--r--src/core/lib/security/context/security_context.cc8
-rw-r--r--src/core/lib/security/context/security_context.h3
-rw-r--r--src/core/lib/security/transport/client_auth_filter.cc6
3 files changed, 11 insertions, 6 deletions
diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc
index dbf6e39577..94c9c69fcd 100644
--- a/src/core/lib/security/context/security_context.cc
+++ b/src/core/lib/security/context/security_context.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 --- */
diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h
index 1e98d169a2..a8e1c3fd64 100644
--- a/src/core/lib/security/context/security_context.h
+++ b/src/core/lib/security/context/security_context.h
@@ -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 ---
diff --git a/src/core/lib/security/transport/client_auth_filter.cc b/src/core/lib/security/transport/client_auth_filter.cc
index 048e390a71..9b5c6f3490 100644
--- a/src/core/lib/security/transport/client_auth_filter.cc
+++ b/src/core/lib/security/transport/client_auth_filter.cc
@@ -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();