diff options
Diffstat (limited to 'src/cpp/common/channel_arguments.cc')
-rw-r--r-- | src/cpp/common/channel_arguments.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 65f3277499..eddcacc332 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -81,6 +81,16 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other) } } +ChannelArguments::~ChannelArguments() { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + for (auto it = args_.begin(); it != args_.end(); ++it) { + if (it->type == GRPC_ARG_POINTER) { + it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); + } + } + grpc_exec_ctx_finish(&exec_ctx); +} + void ChannelArguments::Swap(ChannelArguments& other) { args_.swap(other.args_); strings_.swap(other.strings_); @@ -101,8 +111,10 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { for (auto it = args_.begin(); it != args_.end(); ++it) { if (it->type == mutator_arg.type && grpc::string(it->key) == grpc::string(mutator_arg.key)) { + GPR_ASSERT(!replaced); it->value.pointer.vtable->destroy(&exec_ctx, it->value.pointer.p); it->value.pointer = mutator_arg.value.pointer; + replaced = true; } } grpc_exec_ctx_finish(&exec_ctx); @@ -185,7 +197,7 @@ void ChannelArguments::SetPointerWithVtable( arg.type = GRPC_ARG_POINTER; strings_.push_back(key); arg.key = const_cast<char*>(strings_.back().c_str()); - arg.value.pointer.p = value; + arg.value.pointer.p = vtable->copy(value); arg.value.pointer.vtable = vtable; args_.push_back(arg); } |