[BOLT][NFC] Fix possible use-after-free

If NewName twine has reference to the old name, then after
Section.Name = NewName.str(); this reference is invalidated,
so we cannot use NewName.str() anymore.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D137616
This commit is contained in:
revunov.denis@huawei.com 2022-11-14 13:25:20 +00:00
parent 044fcfa1ed
commit c92ff2a3c4
1 changed files with 2 additions and 2 deletions

View File

@ -2036,9 +2036,9 @@ void BinaryContext::renameSection(BinarySection &Section,
deregisterSectionName(Section);
Section.Name = NewName.str();
Section.setOutputName(NewName);
Section.setOutputName(Section.Name);
NameToSection.insert(std::make_pair(NewName.str(), &Section));
NameToSection.insert(std::make_pair(Section.Name, &Section));
// Reinsert with the new name.
Sections.insert(&Section);