Fix incorrect usage of CUDACachingAllocator (#46605)
Summary:
We need an object to hold the ownership of allocated memory in the scope, instead of directly using the raw pointer.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/46605
Reviewed By: zou3519
Differential Revision: D24453548
Pulled By: ezyang
fbshipit-source-id: d29e5a69afa6c0d9e519849910e04524667d0a26