double free or corruption (fasttop)
Labels: needs reproduction, triaged

### 🐛 Describe the bug

pytoch 2.0
conda install pytorch torchvision torchaudio cpuonly -c pytorch

Based on C ++ custom class, TORCH TENSOR as the inherent attribute, when the program executes the completion of the object degeneration, there is an error **Double Free or Corruption (Fasttop)**. Theoretically TORCH Tensor memory is managed and released by TORCH itself.

    torch::TensorOptions options(torch::kFloat32);
        if (is_train) { options.requires_grad(); }
        if (normal) {
            auto gen_opt = c10::optional<at::Generator>();
            value_tensor = torch::normal(mean, std, {1, dim_size}, gen_opt, options = torch::kFloat32);
        } else {
            value_tensor = torch::rand({1, dim_size}, options = options);
        }
        // torch::DeviceType device = torch::DeviceType::CPU
        value_tensor.to(torch::kCPU);

valgrind log:
```
==1989799== 8 bytes in 1 blocks are still reachable in loss record 299 of 3,796
==1989799==    at 0x483DF0F: operator new(unsigned long) (vg_replace_malloc.c:434)
==1989799==    by 0x9398B29: char const* c10::demangle_type<torch::jit::SRNativeOperatorFunctor_prim_TupleIndex>() (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x5C55771: __static_initialization_and_destruction_0(int, int) [clone .constprop.0] (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==1989799==    by 0x4011CA0: call_init (dl-init.c:30)
==1989799==    by 0x4011CA0: _dl_init (dl-init.c:119)
==1989799==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==1989799== 
==1989799== 8 bytes in 1 blocks are still reachable in loss record 300 of 3,796
==1989799==    at 0x483DF0F: operator new(unsigned long) (vg_replace_malloc.c:434)
==1989799==    by 0x9398BD9: char const* c10::demangle_type<torch::jit::SRNativeOperatorFunctor_prim_RaiseException>() (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x5C55812: __static_initialization_and_destruction_0(int, int) [clone .constprop.0] (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==1989799==    by 0x4011CA0: call_init (dl-init.c:30)
==1989799==    by 0x4011CA0: _dl_init (dl-init.c:119)
==1989799==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==1989799== 
==1989799== 8 bytes in 1 blocks are still reachable in loss record 301 of 3,796
==1989799==    at 0x483DF0F: operator new(unsigned long) (vg_replace_malloc.c:434)
==1989799==    by 0x9398C89: char const* c10::demangle_type<torch::jit::SRNativeOperatorFunctor_prim_Uninitialized>() (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x5C558B3: __static_initialization_and_destruction_0(int, int) [clone .constprop.0] (in /App/conda/envs/conda_xmake_cpu/lib/python3.9/site-packages/torch/lib/libtorch_cpu.so)
==1989799==    by 0x4011B99: call_init.part.0 (dl-init.c:72)
==1989799==    by 0x4011CA0: call_init (dl-init.c:30)
==1989799==    by 0x4011CA0: _dl_init (dl-init.c:119)
==1989799==    by 0x4001139: ??? (in /usr/lib/x86_64-linux-gnu/ld-2.31.so)
==1989799== 
```


### Versions

Collecting environment information...
PyTorch version: 2.0.0
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (conda-forge gcc 12.2.0-19) 12.2.0
Clang version: 15.0.6 (https://github.com/conda-forge/clangdev-feedstock b6cf7124da893bcb57ab1f38c768ea825fabbdb1)
CMake version: version 3.25.0
Libc version: glibc-2.31

Python version: 3.9.16 (main, Mar  8 2023, 14:00:05)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-128-generic-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: 
GPU 0: Tesla V100-SXM2-32GB
GPU 1: Tesla V100-SXM2-32GB
GPU 2: Tesla V100-SXM2-32GB
GPU 3: Tesla V100-SXM2-32GB
GPU 4: Tesla V100-SXM2-32GB
GPU 5: Tesla V100-SXM2-32GB
GPU 6: Tesla V100-SXM2-32GB
GPU 7: Tesla V100-SXM2-32GB

Nvidia driver version: 450.203.03
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.7.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   46 bits physical, 48 bits virtual
CPU(s):                          72
On-line CPU(s) list:             0-71
Thread(s) per core:              2
Core(s) per socket:              18
Socket(s):                       2
NUMA node(s):                    2
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           85
Model name:                      Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
Stepping:                        4
CPU MHz:                         1000.141
CPU max MHz:                     3700.0000
CPU min MHz:                     1000.0000
BogoMIPS:                        4600.00
Virtualization:                  VT-x
L1d cache:                       1.1 MiB
L1i cache:                       1.1 MiB
L2 cache:                        36 MiB
L3 cache:                        49.5 MiB
NUMA node0 CPU(s):               0-17,36-53
NUMA node1 CPU(s):               18-35,54-71
Vulnerability Itlb multihit:     KVM: Mitigation: Split huge pages
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:          Mitigation; PTI
Vulnerability Mmio stale data:   Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:        Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:        Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; SMT vulnerable
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==2.0.0
[pip3] torchaudio==2.0.0
[pip3] torchvision==0.15.0
[conda] blas                      1.0                         mkl    defaults
[conda] cpuonly                   2.0                           0    pytorch
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640    defaults
[conda] mkl-service               2.4.0            py39h7f8727e_0    defaults
[conda] mkl_fft                   1.3.1            py39hd3c417c_0    defaults
[conda] mkl_random                1.2.2            py39h51133e4_0    defaults
[conda] numpy                     1.23.5           py39h14f4228_0    defaults
[conda] numpy-base                1.23.5           py39h31eccc5_0    defaults
[conda] pytorch                   2.0.0               py3.9_cpu_0    pytorch
[conda] pytorch-mutex             1.0                         cpu    pytorch
[conda] torchaudio                2.0.0                  py39_cpu    pytorch
[conda] torchvision               0.15.0                 py39_cpu    pytorch