From 8f3222c4eb3ddcc7ec18e1f175e684f2fb862f94 Mon Sep 17 00:00:00 2001 From: Hope Casey-Allen Date: Thu, 21 Jun 2018 15:25:24 -0700 Subject: [PATCH] Remove allocation in server_auth filter and allocate on the arena instead --- src/core/lib/security/context/security_context.cc | 8 ++++---- src/core/lib/security/context/security_context.h | 5 ++++- src/core/lib/security/transport/server_auth_filter.cc | 2 +- src/core/lib/surface/call.cc | 2 ++ src/core/lib/surface/call.h | 2 ++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/lib/security/context/security_context.cc b/src/core/lib/security/context/security_context.cc index 14051a3f008..dbf6e39577b 100644 --- a/src/core/lib/security/context/security_context.cc +++ b/src/core/lib/security/context/security_context.cc @@ -21,6 +21,7 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/gpr/arena.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/security/context/security_context.h" #include "src/core/lib/surface/api_trace.h" @@ -99,10 +100,10 @@ void grpc_client_security_context_destroy(void* ctx) { } /* --- grpc_server_security_context --- */ - -grpc_server_security_context* grpc_server_security_context_create(void) { +grpc_server_security_context* grpc_server_security_context_create( + gpr_arena* arena) { return static_cast( - gpr_zalloc(sizeof(grpc_server_security_context))); + gpr_arena_alloc(arena, sizeof(grpc_server_security_context))); } void grpc_server_security_context_destroy(void* ctx) { @@ -112,7 +113,6 @@ void grpc_server_security_context_destroy(void* ctx) { if (c->extension.instance != nullptr && c->extension.destroy != nullptr) { c->extension.destroy(c->extension.instance); } - gpr_free(ctx); } /* --- grpc_auth_context --- */ diff --git a/src/core/lib/security/context/security_context.h b/src/core/lib/security/context/security_context.h index e782e4f28fe..1e98d169a2d 100644 --- a/src/core/lib/security/context/security_context.h +++ b/src/core/lib/security/context/security_context.h @@ -26,6 +26,8 @@ extern grpc_core::DebugOnlyTraceFlag grpc_trace_auth_context_refcount; +struct gpr_arena; + /* --- grpc_auth_context --- High level authentication context object. Can optionally be chained. */ @@ -101,7 +103,8 @@ typedef struct { grpc_security_context_extension extension; } grpc_server_security_context; -grpc_server_security_context* grpc_server_security_context_create(void); +grpc_server_security_context* grpc_server_security_context_create( + gpr_arena* arena); void grpc_server_security_context_destroy(void* ctx); /* --- Channel args for auth context --- */ diff --git a/src/core/lib/security/transport/server_auth_filter.cc b/src/core/lib/security/transport/server_auth_filter.cc index a560a4a02e9..0bf91d219e9 100644 --- a/src/core/lib/security/transport/server_auth_filter.cc +++ b/src/core/lib/security/transport/server_auth_filter.cc @@ -214,7 +214,7 @@ static grpc_error* init_call_elem(grpc_call_element* elem, // Create server security context. Set its auth context from channel // data and save it in the call context. grpc_server_security_context* server_ctx = - grpc_server_security_context_create(); + grpc_server_security_context_create(args->arena); server_ctx->auth_context = grpc_auth_context_create(chand->auth_context); calld->auth_context = server_ctx->auth_context; if (args->context[GRPC_CONTEXT_SECURITY].value != nullptr) { diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 556eb234b44..3f26b05c340 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -1113,6 +1113,8 @@ static void recv_trailing_filter(void* args, grpc_metadata_batch* b) { publish_app_metadata(call, b, true); } +gpr_arena* grpc_call_get_arena(grpc_call* call) { return call->arena; } + grpc_call_stack* grpc_call_get_call_stack(grpc_call* call) { return CALL_STACK_FROM_CALL(call); } diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index e000f13e7d3..b3b06059d4d 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -71,6 +71,8 @@ void grpc_call_internal_unref(grpc_call* call); #define GRPC_CALL_INTERNAL_UNREF(call, reason) grpc_call_internal_unref(call) #endif +gpr_arena* grpc_call_get_arena(grpc_call* call); + grpc_call_stack* grpc_call_get_call_stack(grpc_call* call); grpc_call_error grpc_call_start_batch_and_execute(grpc_call* call,