From 4b42047fef34c84c24d3deb8047b32263b8a2bf7 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 1 Oct 2024 15:10:05 +0000 Subject: [PATCH] fix(transformer): fix memory leak in `ReplaceGlobalDefines` (#6224) `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. --- crates/oxc_transformer/src/plugins/replace_global_defines.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/plugins/replace_global_defines.rs b/crates/oxc_transformer/src/plugins/replace_global_defines.rs index 7868806d8..573ff9dff 100644 --- a/crates/oxc_transformer/src/plugins/replace_global_defines.rs +++ b/crates/oxc_transformer/src/plugins/replace_global_defines.rs @@ -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() }