Skip to content

Commit 95aa827

Browse files
authored
Fix value release in ecma_builtin_regexp_dispatch_helper (#3702)
JerryScript-DCO-1.0-Signed-off-by: Adam Szilagyi [email protected]
1 parent aaf0442 commit 95aa827

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-regexp.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**<
5252
ecma_value_t flags_value = ECMA_VALUE_UNDEFINED;
5353
#if ENABLED (JERRY_ES2015)
5454
bool create_regexp_from_bc = false;
55+
bool free_arguments = false;
5556
#endif /* ENABLED (JERRY_ES2015) */
5657

5758
if (arguments_list_len > 0)
@@ -131,9 +132,12 @@ ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**<
131132

132133
if (ECMA_IS_VALUE_ERROR (flags_value))
133134
{
135+
ecma_free_value (pattern_value);
134136
return flags_value;
135137
}
136138
}
139+
140+
free_arguments = true;
137141
}
138142
#else /* !ENABLED (JERRY_ES2015) */
139143
if (ecma_object_is_regexp_object (pattern_value))
@@ -151,6 +155,14 @@ ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**<
151155

152156
if (JERRY_UNLIKELY (new_target_obj_p == NULL))
153157
{
158+
#if ENABLED (JERRY_ES2015)
159+
if (free_arguments)
160+
{
161+
ecma_free_value (pattern_value);
162+
ecma_free_value (flags_value);
163+
}
164+
#endif /* ENABLED (JERRY_ES2015) */
165+
154166
return ECMA_VALUE_ERROR;
155167
}
156168

@@ -164,11 +176,15 @@ ecma_builtin_regexp_dispatch_helper (const ecma_value_t *arguments_list_p, /**<
164176
else
165177
{
166178
#endif /* ENABLED (JERRY_ES2015) */
167-
168179
ret_value = ecma_op_create_regexp_from_pattern (new_target_obj_p, pattern_value, flags_value);
169-
170180
#if ENABLED (JERRY_ES2015)
171181
}
182+
183+
if (free_arguments)
184+
{
185+
ecma_free_value (pattern_value);
186+
ecma_free_value (flags_value);
187+
}
172188
#endif /* ENABLED (JERRY_ES2015) */
173189

174190
if (ECMA_IS_VALUE_ERROR (ret_value))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var obj = {
16+
get source() {
17+
return "Iam"
18+
},
19+
[Symbol.match]: true
20+
}
21+
22+
var regexp = new RegExp(obj);
23+
assert(regexp.source === "Iam");
24+
25+
Object.defineProperty(obj, 'flags', {'get' : function () {throw 42}});
26+
27+
try {
28+
new RegExp(obj);
29+
assert(false);
30+
} catch (e) {
31+
assert(e === 42);
32+
}

0 commit comments

Comments
 (0)