fix a memory leak on return without free (#90372)
This issue is found by static analysis. The allocated object by new may be leaked on early return.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/90372
Approved by: https://github.com/swolchok