Skip to content

Commit

Permalink
fix(transformer): fix memory leak in ReplaceGlobalDefines (#6224)
Browse files Browse the repository at this point in the history
`ReplaceGlobalDefines` was putting a `String` into the arena. `String` allocates on the heap, so this was a memory leak because it didn't get dropped when the allocator is dropped. This was caught by Miri.

Allocate a string slice instead.
  • Loading branch information
overlookmotel committed Oct 1, 2024
1 parent cc57541 commit 4b42047
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a> ReplaceGlobalDefines<'a> {
// Construct a new expression because we don't have ast clone right now.
fn parse_value(&self, source_text: &str) -> Expression<'a> {
// Allocate the string lazily because replacement happens rarely.
let source_text = self.allocator.alloc(source_text.to_string());
let source_text = self.allocator.alloc_str(source_text);
// Unwrapping here, it should already be checked by [ReplaceGlobalDefinesConfig::new].
Parser::new(self.allocator, source_text, SourceType::default()).parse_expression().unwrap()
}
Expand Down

0 comments on commit 4b42047

Please sign in to comment.