From b7e4530861fcc971aee9d867b3b376e31263486c Mon Sep 17 00:00:00 2001 From: Job Bautista Date: Wed, 25 Jan 2023 19:41:09 +0800 Subject: [PATCH] Issue #2083 - Part 5: Fix memory leak in RegExpObject. Based on Mozilla bug 1345177. --- js/src/vm/RegExpObject.cpp | 2 ++ js/src/vm/RegExpObject.h | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/js/src/vm/RegExpObject.cpp b/js/src/vm/RegExpObject.cpp index a5bf4fe8b3..61baadef81 100644 --- a/js/src/vm/RegExpObject.cpp +++ b/js/src/vm/RegExpObject.cpp @@ -975,6 +975,8 @@ RegExpShared::discardJitCode() void RegExpShared::finalize(FreeOp* fop) { + for (auto& comp : compilationArray) + js_free(comp.byteCode); for (size_t i = 0; i < tables.length(); i++) js_free(tables[i]); tables.~JitCodeTables(); diff --git a/js/src/vm/RegExpObject.h b/js/src/vm/RegExpObject.h index 289c4f0dc9..0056c6aee9 100644 --- a/js/src/vm/RegExpObject.h +++ b/js/src/vm/RegExpObject.h @@ -121,7 +121,6 @@ class RegExpShared : public gc::TenuredCell uint8_t* byteCode; RegExpCompilation() : byteCode(nullptr) {} - ~RegExpCompilation() { js_free(byteCode); } bool compiled(ForceByteCodeEnum force = DontForceByteCode) const { return byteCode || (force == DontForceByteCode && jitCode);