gRPC server segfault when going out of scope

  c++, grpc, protocol-buffers

with the following code, I managed to cause a segfault on the server when the client call a server’s method.

std::unique_ptr<grpc::Server> server_;
{
    grpc::ServerBuilder server_builder;
    server_builder.AddListeningPort("localhost:4500", grpc::InsecureServerCredentials());
    MyServiceImpl service;
    server_builder.RegisterService(&service);
    server = server_builder.BuildAndStart();
}
server->Wait();

But if I move server->Wait(); inside the curly bracket, every thing works as expected.

Is this the expected behaviour? As in, it is designed to be like so?

Source: Windows Questions C++

LEAVE A COMMENT