Commit f98c795
Fix use after free (#4559)
In `THPTensor_(_convertToTensorIndexers)`, a `vector<THPIndexTensor>` is
created by constructing `THPTensor`s from sequences/tensors/etc. Each
`THPIndexTensor` is then freed with the following:
```
for (auto& idx : indexers) {
THIndexTensor_(free)(LIBRARY_STATE idx->cdata);
Py_DECREF(idx);
}
```
This is a problem because `Py_DECREF(idx)` will turn `idx->ob_refcnt` to 0 since this function
created the relevant `THPIndexTensor`s and owns them, causing `THPTensor_(dealloc)` to be
called. `THPTensor_(dealloc)` already has a line that calls
`THIndexTensor_(free)(LIBRARY_STATE idx->cdata)`.
So `THIndexTensor_(free)(LIBRARY_STATE idx->cdata)` gets called twice on the same
`cdata`. After the first call frees `cdata`, the second attempts to access flags/members of `cdata` to
determine if it should free it.1 parent 24a4881 commit f98c795
1 file changed
+0
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
829 | 829 | | |
830 | 830 | | |
831 | 831 | | |
832 | | - | |
833 | 832 | | |
834 | 833 | | |
835 | 834 | | |
| |||
890 | 889 | | |
891 | 890 | | |
892 | 891 | | |
893 | | - | |
894 | 892 | | |
895 | 893 | | |
896 | 894 | | |
| |||
909 | 907 | | |
910 | 908 | | |
911 | 909 | | |
912 | | - | |
913 | 910 | | |
914 | 911 | | |
915 | 912 | | |
916 | 913 | | |
917 | 914 | | |
918 | 915 | | |
919 | 916 | | |
920 | | - | |
921 | 917 | | |
922 | 918 | | |
923 | 919 | | |
| |||
0 commit comments