Skip to content

Commit

Permalink
memory leaks are all you need
Browse files Browse the repository at this point in the history
  • Loading branch information
powerboat9 committed Oct 10, 2023
1 parent 2ad8c35 commit eae29a9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gcc/rust/ast/rust-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,11 @@ class MacroRulesDefinition : public VisItem, public LocatedImpl

MacroKind get_kind () const { return kind; }

std::unique_ptr<MacroRulesDefinition> clone_macro_rules_def () const
{
return std::unique_ptr<MacroRulesDefinition> (clone_item_impl ());
}

protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
Expand Down
3 changes: 2 additions & 1 deletion gcc/rust/util/rust-hir-map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
auto it = macroInvocations.find (invoc.get_macro_node_id ());
rust_assert (it == macroInvocations.end ());

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

bool
Expand Down

0 comments on commit eae29a9

Please sign in to comment.