[MemLeak] Fix memory leak from releasing unique ptr (#41883)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/41883
Fix memory leak from releasing unique ptr
Test Plan:
Tested serialization with and without the change.
Heap profile without change:
```
Welcome to jeprof! For help, type 'help'.
(jeprof) top
Total: 7298.4 MB
4025.2 55.2% 55.2% 4025.2 55.2% c10::alloc_cpu (inline)
3195.3 43.8% 98.9% 3195.3 43.8% caffe2::SerializeUsingBytesOrInt32
63.6 0.9% 99.8% 63.6 0.9% __gnu_cxx::new_allocator::allocate (inline)
5.0 0.1% 99.9% 5.0 0.1% google::protobuf::RepeatedField::Reserve
2.5 0.0% 99.9% 2.5 0.0% folly::aligned_malloc (inline)
1.2 0.0% 99.9% 1.2 0.0% caffe2::detail::CopyFromProtoWithCast (inline)
1.0 0.0% 99.9% 1.0 0.0% __new_exitfn
1.0 0.0% 100.0% 1.0 0.0% std::_Function_base::_Base_manager::_M_init_functor (inline)
0.5 0.0% 100.0% 0.5 0.0% folly::HHWheelTimerBase::newTimer (inline)
0.5 0.0% 100.0% 0.5 0.0% std::__detail::_Hashtable_alloc::_M_allocate_node
```
Heap profile with change:
```
Welcome to jeprof! For help, type 'help'.
(jeprof) top
Total: 6689.2 MB
4025.2 60.2% 60.2% 4025.2 60.2% c10::alloc_cpu (inline)
2560.0 38.3% 98.4% 2560.0 38.3% caffe2::::HugePagesArena::alloc_huge (inline)
90.9 1.4% 99.8% 90.9 1.4% __gnu_cxx::new_allocator::allocate (inline)
5.0 0.1% 99.9% 5.0 0.1% google::protobuf::RepeatedField::Reserve
2.0 0.0% 99.9% 2.0 0.0% prof_backtrace_impl (inline)
1.0 0.0% 99.9% 20.3 0.3% std::__cxx11::basic_string::_M_construct (inline)
1.0 0.0% 99.9% 1.0 0.0% std::_Function_base::_Base_manager::_M_init_functor (inline)
0.5 0.0% 99.9% 0.5 0.0% folly::UnboundedQueue::allocNextSegment (inline)
0.5 0.0% 100.0% 0.5 0.0% folly::aligned_malloc (inline)
0.5 0.0% 100.0% 0.5 0.0% __new_exitfn
```
Reviewed By: yinghai
Differential Revision: D22662093
fbshipit-source-id: d0b8ff1ed26c72b14bb02fb1146c51ef11a7e519