[mlir] Fixed double-free bug in SymbolUserMap
authorNandor Licker <n@ndor.email>
Fri, 8 Jul 2022 05:57:37 +0000 (08:57 +0300)
committerNandor Licker <n@ndor.email>
Fri, 8 Jul 2022 17:06:35 +0000 (20:06 +0300)
commitf92d319c70b5893deb33a996af4b5a74e193d66b
tree5e0febaf2a0a948ec553ea37e2bed9277a8e0ccf
parenta246eb681424c59549a7cecd3eb9581253d28f04
[mlir] Fixed double-free bug in SymbolUserMap

`SymbolUserMap` relied on `try_emplace` and `std::move` to relocate an entry to another key.  However, if this triggered the resizing of the `DenseMap`, the value was destroyed before it could be moved to the new storage location, leading to a dangling `users` reference to be inserted into the map. On destruction, since a new entry was created from one that was already freed, a double-free error occurred.

Fixed issue by re-fetching the iterator after the mutation of the container.

Differential Revision: https://reviews.llvm.org/D129345
mlir/lib/IR/SymbolTable.cpp