@@ -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 ))
0 commit comments