title: gRPC C++: AddressSanitizer: bad-free
body: <p>gRPC v1.30.0
  I created a grpc service and tried to run it. The execution goes smooth till the last return statement at server side.</p>
  <pre><code>Status theService(ServerContext *context, const Request* req, Response* res)
  {
          Status status = actualLogic(req,res);   
          //execution goes fine till here 
          return status;
  } 
  
  
  Status actualLogic(req,res)
  {
          Response_NestedMsg msg;
          msg.set_something(...);
          res-&gt;mutable_nestedmsg()-&gt;CopyFrom(msg);
          return Status::OK
  }
  
  //server startup code
  ServerBuilder builder;        
  builder.AddListeningPort((address),grpc::InsecureServerCredentials());
  builder.RegisterService(&amp;serviceClassObj);
  std::unique_ptr&lt;Server&gt; server(builder.BuildAndStart());
  server-&gt;Wait();
  </code></pre>
  <p>Running this code, I get following runtime error</p>
  <pre><code>==14394==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x61b00000fcc8 in thread T5 (grpcpp_sync_ser)
      #0 0x7fe9d35602c0 in operator delete(void*) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe12c0)
      #1 0x55cb87299afd in __gnu_cxx::new_allocator&lt;std::_List_node&lt;grpc_impl::Server const*&gt; &gt;::deallocate(std::_List_node&lt;grpc_impl::Server const*&gt;*, unsigned long) (/home/john/Desktop/my_executable+0xd0afd)
      #2 0x55cb87297ba1 in std::allocator_traits&lt;std::allocator&lt;std::_List_node&lt;grpc_impl::Server const*&gt; &gt; &gt;::deallocate(std::allocator&lt;std::_List_node&lt;grpc_impl::Server const*&gt; &gt;&amp;, std::_List_node&lt;grpc_impl::Server const*&gt;*, unsigned long) (/home/john/Desktop/my_executable+0xceba1)
      #3 0x55cb8729448d in std::__cxx11::_List_base&lt;grpc_impl::Server const*, std::allocator&lt;grpc_impl::Server const*&gt; &gt;::_M_put_node(std::_List_node&lt;grpc_impl::Server const*&gt;*) (/home/john/Desktop/my_executable+0xcb48d)
      #4 0x55cb8728bb5a in std::__cxx11::_List_base&lt;grpc_impl::Server const*, std::allocator&lt;grpc_impl::Server const*&gt; &gt;::_M_clear() (/home/john/Desktop/my_executable+0xc2b5a)
      #5 0x55cb87287307 in std::__cxx11::_List_base&lt;grpc_impl::Server const*, std::allocator&lt;grpc_impl::Server const*&gt; &gt;::~_List_base() (/home/john/Desktop/my_executable+0xbe307)
      #6 0x55cb87278d29 in std::__cxx11::list&lt;grpc_impl::Server const*, std::allocator&lt;grpc_impl::Server const*&gt; &gt;::~list() (/home/john/Desktop/my_executable+0xafd29)
      #7 0x55cb87278e2c in grpc_impl::CompletionQueue::~CompletionQueue() (/home/john/Desktop/my_executable+0xafe2c)
      #8 0x7fe9d1826998 in grpc_impl::Server::SyncRequest::CallData::ContinueRunAfterInterception() (/usr/local/lib/libgrpc++.so.1+0x6f998)
      #9 0x7fe9d18278ee in grpc_impl::Server::SyncRequestThreadManager::DoWork(void*, bool, bool) (/usr/local/lib/libgrpc++.so.1+0x708ee)
      #10 0x7fe9d182c4ca in grpc::ThreadManager::MainWorkLoop() (/usr/local/lib/libgrpc++.so.1+0x754ca)
      #11 0x7fe9d182c68b in grpc::ThreadManager::WorkerThread::Run() (/usr/local/lib/libgrpc++.so.1+0x7568b)
      #12 0x7fe9cf5a78d2 in grpc_core::(anonymous namespace)::ThreadInternalsPosix::ThreadInternalsPosix(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&amp;)::{lambda(void*)#1}::_FUN(void*) (/usr/local/lib/libgpr.so.10+0x118d2)
      #13 0x7fe9d1eef6da in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76da)
      #14 0x7fe9d0ba8a3e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x121a3e)
  
  0x61b00000fcc8 is located 72 bytes inside of 1448-byte region [0x61b00000fc80,0x61b000010228)
  allocated by thread T5 (grpcpp_sync_ser) here:
      #0 0x7fe9d355f448 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0448)
      #1 0x7fe9d18274f2 in grpc_impl::Server::SyncRequestThreadManager::DoWork(void*, bool, bool) (/usr/local/lib/libgrpc++.so.1+0x704f2)
  
  Thread T5 (grpcpp_sync_ser) created by T0 here:
      #0 0x7fe9d34b6d2f in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x37d2f)
      #1 0x7fe9cf5a7a92 in grpc_core::Thread::Thread(char const*, void (*)(void*), void*, bool*, grpc_core::Thread::Options const&amp;) (/usr/local/lib/libgpr.so.10+0x11a92)
  
  SUMMARY: AddressSanitizer: bad-free (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe12c0) in operator delete(void*)
  ==14394==ABORTING
  </code></pre>
  <p>None of my code tries to free any pointer and error seems to be coming from some auto generated file only. Please suggest if some more code/details needed.</p>