Fix some memory bugs in onnx passes (#63754)
authorBert Maher <bertrand@fb.com>
Tue, 24 Aug 2021 00:28:33 +0000 (17:28 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 24 Aug 2021 00:31:45 +0000 (17:31 -0700)
commit172e5c76ab05f1a137eb065b7f221a20eaef514a
tree4973ea97b42a8e7abc398426abb3a83d34dbc47e
parentfc6dd0bc008d1a1872626567506be6e9e5dcbae1
Fix some memory bugs in onnx passes (#63754)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63754

Running onnx tests with ASAN uncovers several memory errors.  These two are caused by: (1) iterating the uses list of a node after mutation, and (2) accessing the `blocks` attribute of a possibly deleted node.

To reproduce (this is on a CentOS 7 box):
```
DEBUG=1 CFLAGS="-fsanitize=address" CXXFLAGS="-fsanitize=address" USE_LLVM=$(realpath ../llvm-project/install) CMAKE_PREFIX_PATH=$CONDA_PREFIX python setup.py install
LD_PRELOAD=$(realpath /lib64/libasan.so.5) numactl -C3 pytest -v --cov --cov-report xml:test/coverage.xml --cov-append onnx/test_pytorch_onnx_onnxruntime.py::TestONNXRuntime_opset11 -s
```

Test Plan: Imported from OSS

Reviewed By: ZolotukhinM

Differential Revision: D30493939

Pulled By: bertmaher

fbshipit-source-id: e16e19dc9b4c9896e102ca8bf04c8bedfdde87af
torch/csrc/jit/passes/onnx/list_model_parameters.cpp
torch/csrc/jit/passes/onnx/pattern_conversion/common.cpp
torch/csrc/jit/passes/onnx/remove_inplace_ops_for_onnx.cpp