Skip to content

Commit eae29a9

Browse files
committed
memory leaks are all you need
1 parent 2ad8c35 commit eae29a9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

gcc/rust/ast/rust-macro.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,11 @@ class MacroRulesDefinition : public VisItem, public LocatedImpl
576576

577577
MacroKind get_kind () const { return kind; }
578578

579+
std::unique_ptr<MacroRulesDefinition> clone_macro_rules_def () const
580+
{
581+
return std::unique_ptr<MacroRulesDefinition> (clone_item_impl ());
582+
}
583+
579584
protected:
580585
/* Use covariance to implement clone function as returning this object rather
581586
* than base */

gcc/rust/util/rust-hir-map.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
917917
auto it = macroInvocations.find (invoc.get_macro_node_id ());
918918
rust_assert (it == macroInvocations.end ());
919919

920-
macroInvocations[invoc.get_macro_node_id ()] = def;
920+
// TODO: remove hack that converts use-after-free into memory leak
921+
macroInvocations[invoc.get_macro_node_id ()] = def->clone_macro_rules_def ().release ();
921922
}
922923

923924
bool

0 commit comments

Comments
 (0)