Skip to content
Snippets Groups Projects
Commit 4564b8cd authored by Yuchen Zeng's avatar Yuchen Zeng
Browse files

Copy value at SetPointerWithVtable

parent 77532e8b
Branches
Tags
No related merge requests found
...@@ -111,8 +111,10 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) { ...@@ -111,8 +111,10 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
for (auto it = args_.begin(); it != args_.end(); ++it) { for (auto it = args_.begin(); it != args_.end(); ++it) {
if (it->type == mutator_arg.type && if (it->type == mutator_arg.type &&
grpc::string(it->key) == grpc::string(mutator_arg.key)) { 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.vtable->destroy(&exec_ctx, it->value.pointer.p);
it->value.pointer = mutator_arg.value.pointer; it->value.pointer = mutator_arg.value.pointer;
replaced = true;
} }
} }
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
...@@ -195,7 +197,7 @@ void ChannelArguments::SetPointerWithVtable( ...@@ -195,7 +197,7 @@ void ChannelArguments::SetPointerWithVtable(
arg.type = GRPC_ARG_POINTER; arg.type = GRPC_ARG_POINTER;
strings_.push_back(key); strings_.push_back(key);
arg.key = const_cast<char*>(strings_.back().c_str()); 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; arg.value.pointer.vtable = vtable;
args_.push_back(arg); args_.push_back(arg);
} }
......
...@@ -230,13 +230,6 @@ TEST_F(ChannelArgumentsTest, SetSocketMutator) { ...@@ -230,13 +230,6 @@ TEST_F(ChannelArgumentsTest, SetSocketMutator) {
EXPECT_TRUE(HasArg(arg1)); EXPECT_TRUE(HasArg(arg1));
// arg0 is replaced by arg1 // arg0 is replaced by arg1
EXPECT_FALSE(HasArg(arg0)); EXPECT_FALSE(HasArg(arg0));
// arg0 is destroyed by grpc_socket_mutator_to_arg(mutator1)
{
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
arg1.value.pointer.vtable->destroy(&exec_ctx, arg1.value.pointer.p);
grpc_exec_ctx_finish(&exec_ctx);
}
} }
TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment