Skip to content

Commit d2f0b3c

Browse files
committed
codegen: fix use-after-free
1 parent 930a5f0 commit d2f0b3c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/codegen.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -5695,10 +5695,15 @@ static std::unique_ptr<Module> emit_function(
56955695
}
56965696
}
56975697
if (!have_real_use) {
5698+
Instruction *use = NULL;
56985699
for (Use &U : root->uses()) {
5700+
if (use) // erase after the iterator moves on
5701+
use->eraseFromParent();
56995702
User *RU = U.getUser();
5700-
cast<Instruction>(RU)->eraseFromParent();
5703+
use = cast<Instruction>(RU);
57015704
}
5705+
if (use)
5706+
use->eraseFromParent();
57025707
root->eraseFromParent();
57035708
if (store_value)
57045709
store_value->eraseFromParent();

0 commit comments

Comments
 (0)