This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Fixed double-free bug in SymbolUserMap
ClosedPublic

Authored by nand on Jul 7 2022, 11:01 PM.

Details

Summary

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.

Diff Detail

Event Timeline

nand created this revision.Jul 7 2022, 11:01 PM
Herald added a project: Restricted Project. · View Herald Transcript
nand requested review of this revision.Jul 7 2022, 11:01 PM
rriddle accepted this revision.Jul 8 2022, 10:05 AM

We could alternatively try to move the users first and then update later, but this is fine as well.

This revision is now accepted and ready to land.Jul 8 2022, 10:05 AM
This revision was automatically updated to reflect the committed changes.