From 09c75705608518da5957d7455ff9db6b4d4eba1b Mon Sep 17 00:00:00 2001 From: Boshen Date: Mon, 15 Jan 2024 23:11:02 +0800 Subject: [PATCH] ci: use miri to detect memory leak for the parser (#2037) We'll merge this and then eventually turn it on as a nightly check, it's a manual run for now. --- .github/workflows/miri.yml | 5 +++-- crates/oxc_parser/src/lib.rs | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/miri.yml b/.github/workflows/miri.yml index c9f9f5957077e..9f3c7c94f4f90 100644 --- a/.github/workflows/miri.yml +++ b/.github/workflows/miri.yml @@ -17,8 +17,9 @@ jobs: - name: Install Miri run: | - rustup component add miri + rustup toolchain install nightly --component miri + rustup override set nightly cargo miri setup - name: Test with Miri - run: MIRIFLAGS="-Zmiri-disable-isolation" cargo miri test + run: cargo miri test -p oxc_parser diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs index 7cce4a0685428..96308407f95a2 100644 --- a/crates/oxc_parser/src/lib.rs +++ b/crates/oxc_parser/src/lib.rs @@ -316,6 +316,17 @@ mod test { } } + #[test] + fn memory_leak() { + let allocator = Allocator::default(); + let source_type = SourceType::default(); + let sources = ["2n", ";'1234567890123456789012345678901234567890'"]; + for source in sources { + let ret = Parser::new(&allocator, source, source_type).parse(); + assert!(!ret.program.body.is_empty()); + } + } + // Source with length u32::MAX + 1 fails to parse #[test] fn overlong_source() {